Change the default editor
$ git config --global core.editor "vim"
View commit history as a graph
$ git config --global alias.lol 'log --oneline --graph --decorate --all'
Delete all local branches
$ git branch | grep -v "master" | xargs git branch -D
Rename current branch
$ git branch -m <new_name>
Rename another branch
$ git branch -m <branch_name> <new_name>
Combine multiple commits
Step 1: Use
git rebase in interactive mode with the parent commit (the commit you would like to start merging from).
$ git rebase -i <parent_commit_it>
$ git rebase -i HEAD~3
This will attempt to merge the last three commits into one.
Step 2: In the next screen,
pick the first commit and
squash the rest.
Step 3: Edit the commit message.
Move commits between branches
Move a commit in another branch to the current branch (cherry-pick)
$ git cherry-pick <commit_id>
Move contents of a commit to staging index
$ git cherry-pick -n <commit_id>
Reverting merge commits
-m option has to be specified when reverting merge commits.
Merge commits have multiple parents and
-m specifies which parent commit to revert to.