All Posts

Useful git tricks

February 17, 2020 • ☕️ 2 min read

In this post we are going to discuss about some very useful trick on Git.

Fix last commit message

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

The -v is 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.

Follow these steps:

  • Open your project directory on your terminal and type the above command.
  • Your editor will open and allow you to make a changes to that last commit message.
  • Save

Change branch name

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

Switch to Previous Branch

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 checkout to co so, it becomes just git co -.

git checkout -

Find Branches

This command will show all branches that contain a particular commit.

git branch --contains <commit>

Cherry Pick

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>

Relative Posts:

Create your first Pull Request

February 20, 2020

Why Cypress?

January 19, 2020