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:
gitreflog
Diff
If you want to check what is the difference between two branches, you can simply do:
gitdiffbranch1..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:
gitshow:/fixes
Limit git push default actions
If you run
gitpush
which 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:
gitconfig--globalpush.defaulttracking
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:
gitrebaseHEADfeature&&gitrebaseHEAD@{-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:
gitconfig--globalalias.cocheckout
Now, you can checkout to master by doing:
gitcomaster
Renaming a local branch
You can easily rename a local branch with:
gitbranch-mold-namenew-name
Searching for an author
You can search for a commit by an author by using:
gitlog--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: