Git cheatsheet
Git is a decentralized version management software. With this cheatsheet, you will have quick access to the most common git commands.
About Git cheatsheet
A one-page Git cheat sheet with the commands you reach for most often, grouped by task: configuring Git, starting a repository, committing, undoing mistakes and miscellaneous day-to-day operations.
When you would use it
- Looking up the exact syntax of a command you use rarely, such as amending a commit or reverting a file.
- Recovering from a mistake (wrong branch, bad commit, accidental add) under pressure.
- Onboarding someone new to Git with a short, practical reference.
How to use it
- Scan the section headings for your task.
- Copy the command and replace the placeholders (branch names, file paths) with your own.
- Use the search in your browser (Ctrl+F) for a keyword.
Things worth knowing
- Commands that rewrite history (amend, rebase, reset --hard, force push) are safe on commits you have not pushed. Once others may have pulled them, prefer git revert, which adds a new commit instead.
- git reset --hard and git checkout -- file discard uncommitted work permanently. Run git stash first if you might want it back.
- git pull is fetch plus merge; many teams prefer git pull --rebase to avoid merge commits on feature branches.
- The sheet covers the command-line client. Graphical clients and IDEs expose the same operations under different names.
Frequently asked questions
- How do I undo my last commit but keep the changes?
- git reset --soft HEAD~1 moves the branch back one commit and leaves the files staged. Use --mixed (the default) to also unstage them, and --hard only if you want to discard the changes.
- What is the difference between git revert and git reset?
- revert creates a new commit that undoes an earlier one, keeping history intact and safe to push. reset moves the branch pointer and rewrites history, so it is for local, unpushed commits.