-
Repository: A project’s folder plus its full history. Syntax:
git init
(start) orgit clone <url>
(copy) -
Clone: Make your own local copy of a remote repo. Syntax:
git clone https://github.com/user/repo.git
-
Commit: Snapshot your staged changes with a note. Syntax:
git commit -m "Describe what you did"
-
Branch: Branch off to work on something new without touching main. Syntax:
git branch feature-login
-
Switch: Move to another branch (or create+move in one step). Syntax:
git switch main
Syntax:git switch -c feature-login
-
Merge: Bring another branch’s work into your current one. Syntax:
git merge feature-login
-
Release: Replay your commits onto another branch (aka rebase). Syntax:
git rebase main
-
Pull: Grab remote updates and merge them in one go. Syntax:
git pull
-
Push: Send your local commits up to the remote repo. Syntax:
git push
-
Fetch: Download what’s new on the remote—but don’t merge yet. Syntax:
git fetch
-
Remote: The saved URL of another copy of your repo. Syntax:
git remote -v
-
Status: See what’s changed, staged, or unstaged right now. Syntax:
git status
-
Add: Stage file edits or new files for your next commit. Syntax:
git add .
-
Log: Scroll through past commits and messages. Syntax:
git log
-
Diff: Peek at exactly what changed between two points. Syntax:
git diff HEAD~1 HEAD
-
Stash: Stash away uncommitted work to come back later. Syntax:
git stash
-
Checkout: (Older) switch branches or restore files/commits. Syntax:
git checkout HEAD~2
-
Tag: Pin a name (like v1.0) to a specific commit. Syntax:
git tag v1.0
-
Reset: Move your branch pointer to undo commits (careful!). Syntax:
git reset --hard HEAD~1
-
Revert: Make a new commit that undoes an old one—safe undo. Syntax:
git revert a1b2c3d
-
Cherry‑Pick: Copy a single commit’s changes into your branch. Syntax:
git cherry-pick a1b2c3d
-
Blame: See who last edited each line of a file. Syntax:
git blame README.md
-
Merge Conflict: Happens when two edits clash—fix the file, then
git add
+git commit
. -
Fork: On GitHub, make your own online copy to experiment safely.
-
Pull Request: On GitHub, ask to merge your branch into the main project.
-
Upstream: The original repo you cloned or forked from. Syntax:
git remote add upstream https://github.com/owner/repo.git
-
HEAD: A pointer to wherever you’re currently working.
-
Origin: The default name for your main remote (set by
git clone
). -
Worktree: Extra working folder tied to a branch. Syntax:
git worktree add ../alt-work main
-
Archive: Bundle a branch or commit into a zip/tar. Syntax:
git archive --format=zip -o release.zip main
-
Clean: Toss out untracked files that you don’t need. Syntax:
git clean -f
-
Ignore: List files or patterns in
.gitignore
so Git skips them. -
Commit Message: One‑line “what” + (optional) longer “why” to explain your snapshot.
-
Commit Graph: See branches & merges in one view. Syntax:
git log --graph --oneline --all
-
Submodule: Nest another repo inside yours; keeps its own history. Syntax:
git submodule add <url> vendor/lib
-
Reflog: Safety-net log that remembers every move, even after resets. Syntax:
git reflog
-
Bisect: Binary-search your history to find which commit broke the build. Syntax:
git bisect start
/git bisect bad
/git bisect good v1.0
-
Squash: Combine several commits into one tidy story. Syntax:
git rebase -i HEAD~3
(mark “squash” in the editor) -
Grep: Search every commit for a string or regex. Syntax:
git grep -n "TODO"
-
Show: Inspect a single commit, tag, or any Git object. Syntax:
git show a1b2c3d
-
Describe: Find the closest tag plus how many commits ahead you are. Syntax:
git describe --tags
-
Hooks: Shell scripts that fire automatically on events like
commit
orpush
. Syntax:.git/hooks/pre-commit
-
Filter-Branch: Rewrite large swaths of history (e.g., remove a file forever). Syntax:
git filter-branch --tree-filter 'rm -f huge.zip' HEAD
-
Bundle: Package the entire repo history into a single file for sneaker-net sharing. Syntax:
git bundle create repo.bundle --all
-
Note: Attach extra text to a commit without changing its hash. Syntax:
git notes add -m "QA sign-off"
-
Garbage Collect: Compress and prune loose objects to shrink repo size. Syntax:
git gc --aggressive
-
Worktree Prune: Remove stale worktree directories after deletion. Syntax:
git worktree prune
-
Sparse-Checkout: Only check out the folders you actually need. Syntax:
git sparse-checkout set client/ server/
-
Config: View or edit Git settings per repo or globally. Syntax:
git config --global user.name "Jane Doe"
-
Alias: Create your own short-hand commands. Syntax:
git config --global alias.graph "log --graph --oneline --all"
-
FSCK: Check the repo for integrity issues and dangling objects. Syntax:
git fsck --full
-
Rerere: Reuse recorded conflict resolutions so you only fix the same clash once. Syntax:
git config --global rerere.enabled true
-
Mailmap: Map multiple author identities to one canonical name/email. Syntax:
.mailmap