When I was a university student, whenever I fucked up my local repository I instantly deleted it and re-cloned it.

I hated git as a student. But once I started investing time to learn git, things finally clicked. I was no longer blowing up my local repository to fix my dumb mistakes.

Here are 3 things that confused me as a newbie:

WTF does origin mean?

You’ve probably seen the word origin frequently when working with git.

There’s nothing special about it. Origin is an alias of the remote repository URL you cloned from. Git creates this alias by default when running the git clone command. If for whatever reason you want to rename origin, you can run the following command:

# Rename origin
$ git remote rename origin cheddar

# Verify the new alias
$ git remove -v

cheddar	git@github.com:maupanelo/coolRepo.git (fetch)
cheddar	git@github.com:maupanelo/coolRepo.git (push)

WTF is the difference between git fetch and git pull?

The commands git fetch and git pull are similar, but one is the safe and nondestructive version.

Both commands download the latest content from the remote. But git fetch doesn’t explicitly integrate the fetched content into your local repository. Running git pull, however, doesn’t ask for permission to merge the fetched content into your local repository.

This makes git fetch the safer command to run.

With git fetch, you can view what others have worked on before merging them into your working changes. This lets you scope out and address any potential merge conflicts before running git merge.

Tl;dr: git pull runs git fetch then git merge.

WTF, git checkout does too many things.

Too many damn things.

It can create and checkout branches, checkout commits, and discard un-staged changes on a file. It can be overwhelming. Even more so when trying to explain the command to junior devs. The Git team is working to split up the many use cases of git checkout into other git commands.

Be aware that these commands are still experimental, and may change in the future.

# Change branch
$ git switch <branchname>

# Create branch
$ git switch -c <branchname>

# Undo unstaged changes on file
$ git restore <filename>

Thanks for reading! Let me know what you think of this post on Twitter.