Development

Git Commands Cheat Sheet

A practical Git commands cheat sheet for setup, branches, commits, remotes, undoing changes, inspection and everyday collaboration.

Git version-control workflow with branches, commits and merge paths
Original concept artwork created for this Circuit Compass guide.

This Git cheat sheet groups commands by job and explains what each one changes. Check git status and git diff before commands that rewrite or discard work.

Create, clone and inspect repositories

CommandPurpose
git initCreate a repository in the current directory.
git clone URLCopy a remote repository.
git statusShow branch and working-tree state.
git log --oneline --graphView compact history and branches.
git diffInspect unstaged changes.
git diff --stagedInspect changes prepared for commit.

Stage and commit changes

git add FILEStage a specific file.
git add -pInteractively stage selected hunks.
git commit -m "message"Create a commit from staged changes.
git restore --staged FILEUnstage a file without discarding its content.
git show COMMITInspect a commit and its patch.

Branches and remotes

git switch -c NAMECreate and switch to a branch.
git merge NAMEMerge a branch into the current branch.
git fetch --all --pruneUpdate remote references and remove stale ones.
git pull --ff-onlyUpdate only when a fast-forward is possible.
git push -u origin NAMEPush a new branch and set its upstream.

Undo safely

git restore FILE discards unstaged edits in a file, so inspect it first. git revert COMMIT creates a new commit that reverses an earlier one and is usually appropriate for shared history. git reset moves references and can discard work depending on its mode; do not copy a reset command without understanding the target and whether the commits are published.

Frequently asked questions

What Git command should I run most often?

Run git status frequently. It shows the current branch and what is staged, modified or untracked.

How do I undo a pushed commit safely?

Use git revert to create a new reversing commit when other people may already have the history.

Sources and further reading

Features, software and prices change. Confirm current details with these sources before making a decision.

Found something that needs updating? Send a correction with the page URL and a supporting source.