Git Cheatsheet

Posted by John Liu on Friday, July 10, 2026

git branch

This command lists all your local branches. Your current branch will have an asterisk (*) next to it.

Local branches only: git branch

Remote branches only: git branch -r

All local and remote branches: git branch -a

On Git version 2.22+, you can use git branch --show-current to explicitly show the current branch

git status

This command shows any uncommitted file changes or sync status with remote server.

git checkout <branch-name>

This command switch between different branch in Git.

On Git version 2.23+, you can use git switch <branch-name>

If the brach does not exist yet and you want to create it, git checkout -b <new-branch-name> or git switch -c <new-branch-name>

switch and keep uncommitted changes

# 1. Save and hide your current changes
git stash

# 2. Switch to your new branch
git switch <new-branch-name>

# 3. Bring your saved changes into this branch if need, or after you switch back to original branch and continue work
git stash pop

If you ever want to check what you have saved in your stash library, you can type git stash list to see a history of your stashed changes.

switch to a remote branch

# 1. Download all latest branches from the cloud
git fetch origin

# 2. Switch to the remote branch (Git automatically creates a local copy)
git switch <remote-branch-name>