Skip to main content

Git Command Cheatsheet

A quick, practical list of the most commonly used Git commands for daily development.
Focused on real-world workflow: staging, branching, reviewing, fixing mistakes, and collaborating.


Basic Commands

Check repo status

git status

View changes (unstaged / staged)

git diff
git diff --staged

Add files to staging

git add <file>
git add .

Commit changes

git commit -m "message"

Branching

List branches

git branch

Create a new branch

git checkout -b feature/new-topic

Switch branch

git checkout main

Working with Remote

Pull latest changes

git pull

Push current branch

git push

Set upstream branch (first push)

git push -u origin <branch>

Fixing Mistakes

Undo last commit (keep changes)

git reset --soft HEAD~1

Undo last commit (discard changes)

git reset --hard HEAD~1

Restore a modified file

git restore <file>

Unstage a file

git restore --staged <file>

Reviewing Code

Show commit history

git log --oneline --graph --decorate

Show details of a commit

git show <commit>

Stash

Save changes

git stash

List stashes

git stash list

Apply last stash

git stash apply

Merging & Rebasing

Merge branch into current

git merge <branch>

Rebase onto another branch

git rebase main

Clean Up

Delete local branch

git branch -d <branch>

Delete remote branch

git push origin --delete <branch>

💡 Notes

  • Prefer git restore over git checkout <file> (modern Git).
  • Prefer git switch when switching branches.
  • Keep commit messages simple, consistent, and meaningful.

✅ Summary

A compact Git reference you can use during development. Feel free to extend with your team’s conventions (branch naming, commit message style, workflow).