Skip to content
Git Cheatsheet — Common Commands Quick Reference

Git Cheatsheet — Common Commands Quick Reference

DodaTech 3 min read

Git commands for setup, staging, branching, merging, remote operations, history inspection, and undo — the essential toolkit for version control.

Setup & Configuration

git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main

Basic Workflow

CommandWhat it does
git initInitialize repo in current dir
git clone <url>Copy remote repo locally
git add <file>Stage changes
git add .Stage all changes
git commit -m "msg"Commit staged changes
git statusShow working tree state
git log --onelineCompact commit history

Branching & Merging

git branch <name>        # create branch
git checkout <name>      # switch branch
git switch <name>        # modern alternative
git checkout -b <name>   # create + switch
git merge <branch>       # merge into current
git branch -d <name>     # delete branch

Remote Operations

CommandWhat it does
git remote -vList remotes
git remote add origin <url>Add remote
git push origin mainPush to remote
git pull origin mainFetch + merge
git fetch originFetch without merge

Undoing Changes

git restore <file>         # discard unstaged changes
git restore --staged <f>   # unstage (keep changes)
git reset HEAD~1           # undo last commit (keep changes)
git reset --hard HEAD~1    # undo + discard changes
git revert <hash>          # safe undo via new commit

Stash

git stash              # save work-in-progress
git stash pop          # restore + remove stash
git stash list         # list stashes
git stash drop         # remove top stash

Diff & Log

git diff                # unstaged changes
git diff --staged       # staged changes
git log --oneline -5    # last 5 commits
git log --graph --all   # visual branch graph
git blame <file>        # who changed what

Tag

git tag v1.0.0              # lightweight tag
git tag -a v1.0.0 -m "msg"  # annotated tag
git push origin --tags      # push all tags

.gitignore

# Common entries
node_modules/
.env
*.log
dist/
.DS_Store

Common Workflows

Feature branch:

git checkout -b feature-x
git add . && git commit -m "Add feature x"
git checkout main && git merge feature-x

Fix last commit:

git add forgotten-file.js
git commit --amend --no-edit
What is the difference between `git pull` and `git fetch`?
git fetch downloads remote changes without modifying your working directory. git pull does fetch + merge (or fetch + rebase with --rebase), updating your current branch. Use fetch when you want to inspect changes before integrating them.
How do I undo a Git commit that has already been pushed?
Use git revert <hash> — it creates a new commit that undoes the changes, which is safe for shared branches. Do NOT use git reset --hard on pushed commits as it rewrites history.
What is the difference between merge and rebase?
git merge creates a new merge commit preserving the full history of both branches. git rebase replays commits from one branch onto another, creating a linear history. Use merge for shared branches, rebase for local cleanup before pushing.

See the complete Git tutorials for advanced workflows.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro