git config --global user.name "Name"Name stamped on every commit.git config --global user.email "you@ex.com"Email stamped on every commit.git config --global color.ui autoColorize Git output for readability.git config --global alias.st statusMakegit sta shortcut.git config --listShow all current settings.
git init★Turn the current folder into a repo.git clone <url>★Copy a remote repo + full history locally.git init <dir>Create a new repo in a named directory.
git status★What's modified, staged, untracked.git add <file>★Stage a file for the next commit.git add .★Stage all changes in this directory tree.git add -pInteractively choose hunks to stage.git diffUnstaged changes (working vs. staged).git diff --stagedStaged changes (staged vs. last commit).git reset <file>Unstage, but keep the working-dir changes.git commit -m "msg"★Snapshot the staged content.git commit -am "msg"Stage all tracked changes + commit.git commit --amendFold staged changes into the last commit.
git branch★List branches (★ marks current).git branch <name>Create a branch at the current commit.git switch <name>★Switch branches (modern form).git switch -c <name>★Create + switch in one step.git checkout <name>Older switch syntax (still works).git merge <branch>★Merge a branch into the current one.git branch -d <name>Delete a merged branch.git branch -D <name>forceDelete even if unmerged (loses work).
git remote add <name> <url>Register a remote (usuallyorigin).git remote -vList remotes and their URLs.git fetch <remote>Download refs — look, don't touch.git pull★Fetch + merge into current branch.git pull --rebaseFetch + rebase (keeps history linear).git push★Upload commits to the tracked branch.git push -u origin <name>★First push: set upstream tracking.git push --tagsTags aren't pushed by default — send them.git push --force-with-leasecareSafer force-push (won't clobber others' work).
git log★Commit history of current branch.git log --oneline★One compact line per commit.git log --graph --decorateASCII branch graph + ref labels.git log --follow <file>History of a file, across renames.git log B..ACommits on A that aren't on B.git show <SHA>Full detail of one commit/object.git blame <file>Who last changed each line.git reflog★Every move HEAD made — your safety net.
git stash★Shelve modified tracked files; clean tree.git stash pop★Re-apply newest stash & remove it.git stash listShow the stash stack.git stash dropDiscard the newest stash.
git tagList all tags.git tag <name>Lightweight tag on the current commit.git tag -a <name> <SHA>Annotated tag on a specific commit.git tag -d <name>Delete a local tag.
git restore <file>★Discard unstaged changes to a file.git revert <SHA>★New commit that undoes one — safe to share.git reset HEAD^Undo last commit, keep working changes.git rebase <branch>Replay commits onto a new base.git rebase -i HEAD~5Interactively squash/reword/drop.git reset --hard <commit>destroysReset tree + index; discards changes.git clean -fddestroysDelete untracked files/dirs (use-nfirst).
git rm <file>Delete file + stage the removal.git rm --cached <file>★Stop tracking, keep file on disk.git mv <old> <new>Rename/move + stage the change.git cherry-pick <SHA>Copy one commit onto current branch.
logs/Ignore a whole directory.*.swpIgnore by wildcard glob.!logs/.gitkeepNegate — re-include one path.git config --global core.excludesfile <f>A global ignore for every repo.
maina branch namev0.1a tag3e887aba commit SHA (short is fine)origin/maina remote-tracking branchHEADthe current commitHEAD~33 commits before HEAD