Git cheat sheet
The Git commands you reach for every day, and the ones that get you out of trouble. Click a command to copy it.
Nothing matches your search.
Setup
- Set the name on your commits
- Set the email on your commits
- Name the first branch “main” in new repos
- Start a repository in the current folder
- Download a repository
Everyday
- See what changed and what is staged
- Stage a file for the next commit
- Stage every change, including deleted files
- Pick changes to stage piece by piece
- Commit what is staged with a message
- Show changes that aren’t staged yet
- Show changes that will be committed
Branches
- List branches
- Create a branch and switch to it
- Switch to a branch
- Merge a branch into the current one
- Replay your commits on top of main
- Delete a merged branch (-D to force)
Remotes
- List remotes and their URLs
- Connect a remote
- Download new commits without changing your files
- Fetch and merge the remote branch
- Fetch and put your commits on top
- Push a new branch and track it
- Push commits on a tracked branch
- Overwrite the remote branch, unless someone else pushed
Undoing things
- Throw away unstaged changes to a file
- Unstage a file but keep the changes
- Change the last commit (message or content)
- Undo the last commit, keep the changes staged
- Undo the last commit and delete its changes
- Add a commit that undoes an earlier one (safe for shared branches)
- Find “lost” commits after a reset or rebase
- Delete untracked files and folders
Stash
- Put changes aside for later
- Stash including new, untracked files
- List stashes
- Bring back the latest stash and remove it
- Delete the latest stash
History
- Compact history with branches drawn
- History of a file with its changes
- Show one commit
- Who last changed each line
- Tag the current commit
- Push tags
<url>, <file> and <commit> are placeholders: replace them, angle brackets included.

