git tips and tricks

Feb 13, 2014

Some git tips and tricks that I compiled over time. Do you have any to share?

How do I change the author of my commits?

Sometimes it happens that you commit from different computers with different author and email configurations.

If you prefer consistency, the following steps can help remedy that:

Reset the git commits author

git filter-branch --commit-filter \
'export GIT_AUTHOR_NAME="Author Name"; \
export GIT_AUTHOR_EMAIL=authoremail; \
export GIT_COMMITTER_NAME="Committer Name"; \
export GIT_COMMITTER_EMAIL=committeremail; \
git commit-tree "$@"'

Push the changes to remote

git push -u -f origin --all
  • -u Most of commits will be out of sync after that change, so this is useful to refresh the association between local branches and remote
  • -f Force push
  • –all Push all branches

Keep your clone in-sync

git fetch origin master
git reset --hard origin/master

E voilà!

Source: could I change my name and surname in all previous commits?

How many lines of code do I have?

Reading “How many lines of code is Facebook?” question, I found this git gem:

git ls-files | xargs cat | wc -l

Tags