This post is not intended to be about basic git stuff, but stuff you probably didn't know about or used just once or twice.
-
Recover a commit from reset --HARD
Just use:git reflog
-
Diff
If you want to check what is the difference between two branches, you can simply do:git diff branch1..branch2
-
Show a commit that matches a regex
You can find the last commit in with the message contains the string that was passed, in this case fixes, using the following command:git show :/fixes
-
Limit git push default actions
If you runwhich is the default action is to push all branches on the remote. That can cause many accidents, if you want to prevent them, do this:git push
git config --global push.default tracking
UPDATE: Git 2.0 removed this default http://blog.nicoschuele.com/posts/git-2-0-changes-push-default-to-simple
-
Checkout a branch, rebase and merge to master
Do this magic:git rebase HEAD feature && git rebase HEAD @{-2}
-
Git stash
If you can't commit, because you did not finish your work yet, but something urgent comes up you can use git stash to save those changes, commit your urgent task and then git stash pop to bring your stuff back. -
Aliases
Tired of typing checkout again and again? Go ahead and:git config --global alias.co checkout
Now, you can checkout to master by doing:
git co master
-
Renaming a local branch
You can easily rename a local branch with:git branch -m old-name new-name
-
Searching for an author
You can search for a commit by an author by using:git log --author=jrakesh
-
Status with options
Most people just use git status, but you can pass arguments to change the way status is shown. With the command:git status -sb
you have an output like this:
## master M Gemfile M Gemfile.lock M app/controllers/home_controller.rb M app/views/home/index.html.erb