Git command snippets

Copy-paste-ready Git commands for branching, merging, reverting, stashing, and log inspection.

Git command snippets

Copy-paste-ready Git commands for branching, merging, reverting, stashing, and log inspection.

View a Condensed Git Commit History

git log shows a one-line-per-commit view with branch graph:

git log --oneline --graph --all

Discard All Uncommitted Changes in Git

git checkout restores all files to the last committed state:

git checkout -- .

Stash Uncommitted Changes in Git

git stash saves work in progress without committing:

git stash
git stash pop

Show Files Changed in the Last Git Commit

git show lists files modified in the most recent commit:

git show --stat HEAD

Find Which Git Commit Introduced a Bug

git bisect performs a binary search through commit history:

git bisect start
git bisect bad HEAD
git bisect good abc1234

Delete a Local Git Branch

git branch removes a merged branch:

git branch -d feature/old-branch

Delete a Remote Git Branch

git push removes a branch from the remote:

git push origin --delete feature/old-branch

Show the Current Git Branch Name

git branch displays the active branch:

git branch --show-current