0% found this document useful (0 votes)
6 views2 pages

Git Cheatsheet

This document is a comprehensive cheatsheet for Git commands, covering various functionalities such as branching, merging, committing, and remote operations. It includes commands for setting up configuration, managing stashes, tags, and submodules, as well as safety tips for destructive operations. The format is organized in a multi-column layout for quick reference to essential Git commands.

Uploaded by

Abhisheq Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Git Cheatsheet

This document is a comprehensive cheatsheet for Git commands, covering various functionalities such as branching, merging, committing, and remote operations. It includes commands for setting up configuration, managing stashes, tags, and submodules, as well as safety tips for destructive operations. The format is organized in a multi-column layout for quick reference to essential Git commands.

Uploaded by

Abhisheq Verma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Diffs:

Git Command Branching git diff | git diff --staged | git log -p

Cheatsheet List/create:
git branch | git branch <name>
Blame:
git blame <file> | git annotate <file>
(Multi■column quick reference) Switch:
Stash
git switch <name> | git checkout <name>
Setup & Config Save/apply:
Create+switch:
git stash push -m "msg" | git stash apply
Set name/email: git switch -c <name> | git checkout -b
git config --global user.name "Your <name> List/show:
Name"; git config --global user.email git stash list | git stash show -p
"[email protected]" Delete:
stash@{0}
git branch -d <name> | git branch -D
Editor/merge tool: <name> Pop/drop/clear:
git config --global core.editor "code git stash pop | git stash drop | git
--wait"; git config --global merge.tool Merging & Rebasing stash clear
vimdiff
Merge:
Check config: Tags & Releases
git merge <branch> | git merge --no-ff
git config --list --show-origin Create/list:
Rebase:
Help: git tag v1.0.0 | git tag
git rebase <branch> | git rebase -i
git help <cmd> | git <cmd> -h <base> Annotated:
git tag -a v1.0.0 -m "msg"
Create / Clone Abort/continue:
git merge --abort | git rebase Delete/push:
Init new repo: --abort/--continue git tag -d v1.0.0 | git push origin
git init | git init -b main --tags
Clone: Remote Sync
git clone <url> | git clone --depth 1 Fetch/pull/push:
Undo & Fix
<url> git fetch | git pull | git push Restore file:
Add remote: git restore <file> | git checkout --
Push new branch:
git remote add origin <url> | git remote <file>
git push -u origin <name>
-v Discard local:
Set upstream:
git reset --hard | git clean -fd
Staging & Commit git branch
--set-upstream-to=origin/<name> Reset head:
Stage files: git reset --soft/--mixed/--hard <rev>
git add <file> | git add . | git add -p Prune:
git fetch -p | git remote prune origin Revert commit:
Unstage: git revert <rev> | git revert -n <rev1>
git restore --staged <file> | git reset Inspect & Diff <rev2>
<file>
Status/log:
Commit: History & Search
git status | git log --oneline --graph
git commit -m "msg" | git commit -am --decorate Find by text:
"msg"
git grep -n "pattern" | git log -S"text"
Show commit:
Amend: git show <rev> | git show :<path>
git commit --amend | git commit --amend
--no-edit
Find by file: Global ignore:
git log -- <file> | git log --follow echo "*.log" >> ~/.gitignore_global; git
<file> config --global core.excludesfile
~/.gitignore_global
Pick range:
git log <since>..<until> | git log Ref Plumbing (advanced)
<branchA>.. <branchB>
Refs & reflog:
Collab / Review git show-ref | git reflog | git
update-ref -d <ref>
Worktree:
git worktree add ../wt <branch> | git Cat■file:
worktree list git cat-file -t <rev> | git cat-file -p
<rev>
Cherry-pick:
git cherry-pick <rev> | git cherry-pick Rev■parse:
-n <rev> git rev-parse HEAD | git rev-list
--max-count=10 HEAD
Format-patch:
git format-patch -1 <rev> | git am Safety Tips
<patch.mbox>
Before destructive ops:
Submodules git status; git stash; git branch; git
log --oneline -n 10
Add/update:
git submodule add <url> path Back up WIP:
git commit -m "WIP" or git stash; create
Init/sync: tmp branch
git submodule update --init --recursive
Pull latest:
git submodule update --remote --merge

Sparse & Large Repos


Sparse checkout:
git sparse-checkout init | git
sparse-checkout set <paths>
Shallow fetch:
git fetch --depth 1
LFS note:
Use Git LFS for large binaries: git lfs
install; git lfs track "*.bin"

Clean & Ignore


Clean dry■run:
git clean -n | git clean -fdx

You might also like