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 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 <>"

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

Your first commit – How to start using git

git is a version control system that allows you to keep track of all the changes you make to your code, writing and anything text. Instead of saving the current state of your files, git saves the changes you make to files.

Imagine you create a file called “my_file.txt” and later this to your git history.

This change will look like this.

`— /dev/null` means this was created out of nowhere (a new file)

`+++ b/my_file.txt` is the name of your new file


Platforms to host git projects:

Github, Bitbucket, GitLab

Step by step

  1. Create an account
  2. Create a repository
  3. Create a new git repo on your local machine
    1. git status – to check your status
  4. Direct your local repo to track a git url (your new repo)
  5. Commit your changes
    1. git add <file_name>- to add the files
    2. git commit – to track a change
    3. Add your commit message (“yay first commit”)
  6. Push


Git has a ton of gotchas that can trip up a beginner:

Check out common git gotchas