← Free Resources
📝 Notes & Code⭐ Featured

🐙 Git Cheat Sheet

✍️ UyTech📅 Jul 6, 2026📝 8 blocks

Essential Git commands every developer needs — from init to rebase.

bash

Setup

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global core.editor "code --wait"
bash

Create & Clone

git init                     # initialise a new repo
git clone <url>              # clone remote repo
git clone <url> <dir>        # clone into a specific folder
bash

Stage & Commit

git status                   # show working tree status
git add .                    # stage all changes
git add <file>               # stage specific file
git commit -m "message"      # commit with message
git commit --amend           # amend last commit
bash

Branch

git branch                   # list branches
git branch <name>            # create branch
git checkout <name>          # switch branch
git checkout -b <name>       # create + switch
git branch -d <name>         # delete branch
git merge <branch>           # merge branch into current
bash

Remote

git remote -v                # list remotes
git remote add origin <url>  # add remote
git push origin <branch>     # push branch
git pull origin <branch>     # pull branch
git fetch --all              # fetch all remotes
bash

Undo

git reset HEAD <file>        # unstage file
git checkout -- <file>       # discard changes in file
git revert <commit>          # revert a commit
git reset --hard HEAD~1      # delete last commit (destructive!)
bash

Stash

git stash                    # stash current changes
git stash pop                # apply + drop latest stash
git stash list               # list stashes
git stash drop               # drop latest stash
bash

Log & Diff

git log --oneline            # compact log
git log --oneline --graph    # branch graph
git diff                     # unstaged changes
git diff --staged            # staged changes
git show <commit>            # show a commit
Tags:#git#version-control#commands

Want to test your skills?

Real interview questions from top tech companies