Fix common mistakes while working with git

Saibal Roy • April 4, 2020

quick-tips productivity-tips git

Hello Everyone!

Welcome to my website and this is Saibal with yet another post to share my knowledge with you all.

Everybody is not perfect. So, mistakes do happen when working with git too.

Mistake 1: Typo mistakes done with the commit message. I think most of us fall into this a number of times.

Solution:

git commit --amend -m "an updated commit message"

Check out to understand much better

Mistake 2: If you have seperate git accounts for office and personal work then this issue quite happens that you commit with the wrong account. After doing several commits you realize it. Couple of workarounds with the scenarios are listed below.

If it's only for the last commit you can easily change it with this one line command. Cool and awesome!

git commit --amend --author="John Doe <john@doe.org>"

If it's a git branch where only you were working:

git filter-branch -f --env-filter "GIT_AUTHOR_NAME='John Doe'; GIT_AUTHOR_EMAIL='john@doe.org'; GIT_COMMITTER_NAME='John Doe'; GIT_COMMITTER_EMAIL='john@doe.org';" HEAD

Never fear doing mistakes it helps you learn even better.

Happy learning folks!