Batch 01 · Aarambh — AWS + Agentic AI starts 28 June 2026Batch 01 · Aarambh — AWS + Agentic AI starts 28 June 2026Batch 01 · Aarambh — AWS + Agentic AI starts 28 June 2026Batch 01 · Aarambh — AWS + Agentic AI starts 28 June 2026Batch 01 · Aarambh — AWS + Agentic AI starts 28 June 2026Batch 01 · Aarambh — AWS + Agentic AI starts 28 June 2026Batch 01 · Aarambh — AWS + Agentic AI starts 28 June 2026Batch 01 · Aarambh — AWS + Agentic AI starts 28 June 2026
All cheatsheets
Git · Cheatsheet

Git Cheatsheet — Daily Commands + Rescue Operations

Everyday git, plus the rescue commands you'll Google at 2 AM: reflog, cherry-pick, interactive rebase, and how to un-break a force-push.

Updated 2026-05-21 9 min

Setup & config

git config --global user.name 'You'Set author name
git config --global user.email 'you@x.com'Set author email
git config --global init.defaultBranch mainDefault branch = main
git config --global pull.rebase trueRebase on pull (no merge bubbles)
git config --global core.autocrlf inputLinux line endings on commit
git config --global alias.lg 'log --oneline --graph --all'Pretty log alias

Branching

git switch -c feature/xCreate + checkout branch
git branch -aList all branches (local + remote)
git branch -d feature/xDelete merged branch
git branch -D feature/xForce delete
git push origin --delete feature/xDelete remote branch
git fetch -pFetch + prune stale remote refs

Committing

git add -pStage hunks interactively (review every change)
git commit -m 'feat: x' -m 'body'Subject + body in one line
git commit --amend --no-editAdd staged files to last commit
git commit --fixup <sha>Marked for autosquash on rebase
git restore --staged fileUnstage without losing changes
git restore fileDiscard local edits (DANGER)

Rebase & merge

git rebase mainReplay your commits on top of main
git rebase -i HEAD~5Interactive: squash, reword, drop, reorder
git rebase --autosquash -i mainApply --fixup commits automatically
git merge --no-ff feature/xForce a merge commit (preserves history)
git rebase --continue / --abortAfter resolving conflicts

Stash, cherry-pick, tag

git stash push -m 'wip'Stash with message
git stash list / pop / applyList / restore + delete / restore + keep
git cherry-pick <sha>Apply one commit onto current branch
git cherry-pick -x <sha>Adds 'cherry picked from' to message
git tag -a v1.0 -m 'release'Annotated tag
git push origin v1.0Push a single tag

Inspecting history

git log --oneline --graph --allVisual history
git log -S 'searchText'Find commits adding/removing that string
git log -p filePer-line history of a file
git blame fileWho last touched each line
git diff --statFiles changed + insertions/deletions
git show <sha>Patch for a single commit

🚨 Rescue operations

git reflogTime machine — every HEAD move, even after reset
git reset --hard HEAD@{2}Jump back to a reflog state
git reset --soft HEAD~1Undo last commit, keep changes staged
git reset --mixed HEAD~1Undo last commit, unstage changes
git reset --hard origin/mainDiscard everything, match remote (DANGER)
git revert <sha>Create a NEW commit that undoes <sha>
git checkout <sha> -- fileRestore single file from a past commit
git fsck --lost-foundFind dangling commits/blobs (after force-push)
git push --force-with-leaseForce push BUT abort if remote moved

Worktrees & submodules

git worktree add ../hotfix mainCheck out main in a sibling folder
git worktree list / removeManage worktrees
git submodule update --init --recursivePull submodule contents

Want the full hands-on training behind this?

Cloudadhar batches walk you through every command in a real production setup — with labs, code reviews, and 1:1 doubt sessions.