Git cheat sheet for beginners

Git has a lot of commands, but you do not need most of them on your first day. This is the small set I would keep nearby while learning the normal edit, stage, commit, and share workflow.

Create or copy a repository

Start a repository in the current directory:

git init

Or copy an existing remote repository:

git clone <repository>

Cloning also configures the original repository as a remote, usually named origin.

See what changed

git status

I use git status constantly. It shows changed and untracked files, what is staged, and which branch is active.

To inspect the actual unstaged changes:

git diff

Stage and commit

git add <file>
git commit -m "Describe the change"

Staging is useful because a commit does not need to contain every changed file. I prefer small commits that explain one coherent change over a single “misc fixes” commit at the end of the day.

Work with a remote

git push
git pull

git push sends local commits to the remote repository. git pull fetches and integrates remote changes; because it changes the working copy, check git status and commit important local work first.

Use branches

git branch <branch-name>
git checkout <branch-name>
git merge <branch-name>

These commands create a branch, switch to it, and merge it into the branch currently checked out. Newer Git versions also provide git switch for changing branches. The older checkout command remains common, so it is worth recognising both.

This is enough for a normal first workflow. When something goes wrong, stop and inspect git status before trying a command copied from the internet. Git usually tells you more than its reputation suggests.