git gotchas

Gotcha 1: git config?

“Oops, I’ve been using git without setting my git config?”

If youdon’t set your computers git config, it’ll likely choose a default email for you – something like Patrick@MacBookAir.com. That means, even if you push this to Github, your account will not get the commits.

How to config your git author

First check git log to see that the “author” is correct, if not, follow these steps to fix it

Step 1: Set the right “author” set on your computer

Run $ git config --global --edit and update your author name and email

Step 2: If the author is wrong, update the author on your latest commit

Run git commit --amend --author="Your Name <name@domain.com>"

Congrats, you have changed history!

* This gotcha has a gotcha! You can change the author to any author

Gotcha 2: git rebase or git reset

“I’ve rebased or reset and changed local history, but now I can’t push to my remote branch”

How to change world history (your remote branches) 

If no one has pulled your code, then you are in the clear, however if this is a team project in ANY WAY, this will be dangerous. In general, avoid this situation at all costs.

If you already pushed and NO ONE HAS PULLED YOUR BRANCH, push with force

Run git push -f origin master because you’re a brave soul (this will force your remote branch to update even though you have been changing history)

* anyone who has already pulled can also checkout the branch with force

git checkout -f origin/master