GtGit · Lesson 8 of 8

Git Cheatsheet

The commands you run daily, plus the rescue toolbox — one page.

Bash
# ── Daily loop ──────────────────────────
git status                  # what's going on (run constantly)
git add file.js             # stage one file
git add .                   # stage everything
git commit -m "Add login"
git log --oneline --graph   # history
git diff                    # unstaged changes
git diff --staged           # staged changes

# ── Branches ────────────────────────────
git branch                  # list
git switch -c feature-x     # create + switch
git switch main             # switch back
git merge feature-x         # merge into current branch
git branch -d feature-x     # delete merged branch

# ── Remotes ─────────────────────────────
git clone URL
git push                    # upload commits
git push -u origin feature-x   # first push of a branch
git pull                    # download + merge
git fetch                   # download only
git remote -v               # list remotes
Bash
# ── Undo toolbox ────────────────────────
git restore file.js               # discard unstaged edits
git restore --staged file.js      # unstage, keep edits
git commit --amend -m "Better"    # fix last commit
git revert abc123                 # safe undo (new commit)
git reset --soft HEAD~1           # uncommit, keep staged
git reset --hard HEAD~1           # DESTROY last commit + changes

git stash                         # shelve work-in-progress
git stash pop                     # bring it back
git reflog                        # EVERYTHING that happened
git reset --hard HEAD@{1}         # time-travel via reflog

# ── Inspection ──────────────────────────
git log -p file.js                # commits + diffs for a file
git log -S "functionName"         # commits touching this string
git blame file.js                 # who wrote each line
git show abc123                   # one commit in full
git bisect start                  # binary-search for a bug

# ── Conflicts ───────────────────────────
# <<<<<<< HEAD your side ======= their side >>>>>>>
# edit file, remove markers, then:
git add file.js && git commit
git merge --abort                 # or: bail out

# ── Config once per machine ─────────────
git config --global user.name  "Your Name"
git config --global user.email "you@example.com"
git config --global init.defaultBranch main