Git command cheat sheet from tested examples
Each command here appears in a situation page where its output is shown.
Before you run anything destructive
- Run
git statusand read it. - Save work you might want:
git branch backupcosts nothing. - Remember that
git reflogcan recover many mistakes for a while. The defaults, from the Git documentation, are 90 days for entries that can still be reached and 30 days for those that cannot.
Sources
- Git documentation: git-reset (git-scm.com/docs/git-reset)
- Git documentation: gitrevisions (git-scm.com/docs/gitrevisions)
- Git documentation: git-config, settings gc.reflogExpire and gc.reflogExpireUnreachable (git-scm.com/docs/git-config)
- Git documentation: git-revert (git-scm.com/docs/git-revert)
Read on 14 November 2026.
This is an independent guide. It is not connected with the Git project, GitHub, GitLab or any company named here. Every command below was run on 14 November 2026 with the real program (git version 2.56.0.windows.4) in a new empty practice repository; the output shown is what it printed. Facts about options were read in the official Git documentation on 14 November 2026.