Quite often when you are working in a branch in Git, you want to push the committed stuff to the server side. You’d do the following.
git push origin my_long_branch_name_that_has_description_of_this_branch
You can set a global option for “git push” to push the code to the current branch by executing the following command.
git config --global push.default current
Now you can just type…
This saves me so many keyboard typing and copy and paste of the current branch names.
When I want to totally undo the changes I have made, I do…
git reset --hard
This command doesn’t clean newly added but untracked (staged) files. To clean the files…
git clean -fd
How do we unstage staged files in Git? Say you want to unstage file1 in current directly. Here is the command.
$ git reset -- file1
If you need to unsage all files….
$ git reset
There may be a branch someone else pushed to the server and you want to work with it. What should you do? Here is how you can accomplish.
First, create a local branch out of the remote branch.
$ git fetch origin remote-branch-name:remote-branch-name
Now checkout the branch.
$ git checkout remote-branch-name
You don’t really want to do something like…
$ git pull origin remote-branch-name
This will get the source from the remote-branch-name branch and merge the code into the master (or whichever you have checked out) branch automatically unless you have a conflict. I had to do git reset –hard [the commit ID] to undo it.