Learn Programming, Tech & Coding · Free Online Tools

IT Question Answer
Back to Cheatsheet
Git Commands Cheat Sheet

Git Commands Cheat Sheet

Cheatsheet2,210 viewsBy Admin
cheatsheetcommandscheatsheet

Git Cheat Sheet

All the essential Git commands organized for quick reference.

Setup

git config --global user.name "Name"
git config --global user.email "email"
git init
git clone <url>

Daily Use

git status          # check changes
git add .           # stage all
git commit -m "msg" # commit
git push            # upload
git pull            # download

Branching

git branch                 # list
git checkout -b new-branch # create + switch
git switch main            # switch
git merge feature          # merge
git branch -d feature      # delete

Undo

git restore file           # discard changes
git restore --staged file  # unstage
git reset --hard HEAD~1    # undo commit (careful)
git revert <hash>          # safe undo

Inspect

git log --oneline   # history
git diff            # changes
git show <hash>     # commit details

Remote

git remote -v             # list remotes
git fetch                 # download (no merge)
git push -u origin main   # first push

FAQs

reset vs revert?

reset rewrites history; revert safely undoes with a new commit. More in our cheat sheets and Git guides.

How do I undo the last commit?

git reset --soft HEAD~1 keeps your changes.