February 17, 2020 • ☕️ 2 min read
In this post we are going to discuss about some very useful trick on Git.
Have this ever happened to you that you actually want to commit “Final comment” but what you actually typed is “Final commment”. This is not good if others see this.
git commit -v --amend
-vis optional, but I like it because it shows a lot of information about the changes which helps me to write a more descriptive commit message.
You wanted to create a branch name as release but somehow you named your branch relaese. Don’t panic, there’s a solution for this too.
If you are on the branch you want to rename:
git branch -m new-name
If you are on a different branch:
git branch -m old-name new-name
Rename remote branch name:
git push origin -u new-name
This command allows you to quickly switch to the previously checked out branch. On a general note
- is an alias for the previous branch. It can be used with other commands as well. I aliased
co so, it becomes just
git co -.
git checkout -
This command will show all branches that contain a particular commit.
git branch --contains <commit>
The command git cherry-pick is typically used to introduce particular commits from one branch within a repository onto a different branch. A common use is to forward- or back-port commits from a maintenance branch to a development branch.
git cherry-pick <commit-hash>