Complete GitHub Reference Guide: From Git Basics to gh CLI Mastery
BASIC COMMANDS
| Command | Description |
|---|---|
git init | Create new repository |
git clone <url> | Copy existing repo |
git status | Check what changed |
git add <file> | Stage a file |
git add . | Stage all files |
git commit -m "msg" | Save snapshot |
git log --oneline | View commit history |
git diff | See unstaged changes |
BRANCHING
| Command | Description |
|---|---|
git branch | List all branches |
git branch <name> | Create new branch |
git switch <name> | Switch to branch |
git switch -c <name> | Create + switch |
git merge <branch> | Merge into current |
git branch -d <name> | Delete branch |
SYNC WITH GITHUB
| Command | Description |
|---|---|
git remote add origin <url> | Link to GitHub |
git push -u origin main | First push |
git push | Upload commits |
git pull | Download + merge |
git fetch | Download only |
UNDO CHANGES
| Command | Description |
|---|---|
git reset <file> | Unstage a file |
git reset --soft HEAD~1 | Undo commit (keep changes) |
git reset --hard HEAD~1 | Undo commit (delete changes) |
git checkout -- <file> | Discard file changes |
git commit --amend -m "new" | Rewrite last message |
GITHUB CLI (gh)
| Command | Description |
|---|---|
gh auth login | Login to GitHub |
gh repo create <name> | Create repository |
gh pr create | Create pull request |
gh pr checkout <#> | Checkout PR locally |
gh issue list | View open issues |
gh issue create | Create new issue |
COMMON ERRORS
| Error | Solution |
|---|---|
fatal: not a git repository | Run git init or git clone |
rejected (non-fast-forward) | Run git pull then git push |
detached HEAD | Run git switch <branch> |
| Merge conflicts | Edit files → git add → git commit |
.GITIGNORE ENTRIES
| Entry | Ignores |
|---|---|
node_modules/ | Node packages |
.env | Environment variables |
.DS_Store | Mac system files |
dist/ | Build output |
*.log | Log files |
coverage/ | Test coverage |
STASHING
| Command | Description |
|---|---|
git stash | Save uncommitted work |
git stash list | View stashes |
git stash pop | Apply + remove stash |
git stash apply | Apply keep stash |
git stash drop | Delete stash |
TAGS
| Command | Description |
|---|---|
git tag v1.0 | Create tag |
git tag | List all tags |
git push origin v1.0 | Push tag to GitHub |
git push --tags | Push all tags |
git tag -d v1.0 | Delete local tag |
USEFUL ALIASES
| Alias Command | Shortcut For |
|---|---|
git config --global alias.co checkout | git co |
git config --global alias.br branch | git br |
git config --global alias.st status | git st |
git config --global alias.unstage 'reset HEAD --' | git unstage |
git config --global alias.last 'log -1 HEAD' | git last |
VIEWING HISTORY
| Command | Description |
|---|---|
git log --oneline --graph | Pretty history tree |
git log --author="name" | Filter by author |
git log --since="2 days ago" | Time filter |
git show <commit-id> | See commit details |
PULL REQUEST WORKFLOW
| Step | Command/Action |
|---|---|
| 1 | git checkout -b feature |
| 2 | Make changes to code |
| 3 | git add . |
| 4 | git commit -m "message" |
| 5 | git push origin feature |
| 6 | Open GitHub → Click “Compare & pull request” |
| 7 | Request review |
| 8 | Merge after approval |
MARKDOWN FOR README
| Syntax | Result |
|---|---|
# Title | H1 heading |
## Subtitle | H2 heading |
**bold** | bold |
*italic* | italic |
- item | bullet point |
1. item | numbered list |
[text](url) | hyperlink |
`code` | inline code |
```code block``` | code block |
1000
GITHUB CHEATSHEET (1000+ Rows – Complete Reference)
SECTION 1: GIT CONFIGURATION
| Command | Description |
|---|---|
git config --global user.name "Name" | Set username |
git config --global user.email "email" | Set email |
git config --global --list | List all config |
git config --global core.editor "code --wait" | Set VS Code as editor |
git config --global init.defaultBranch main | Set default branch name |
git config --global alias.co checkout | Create alias for checkout |
git config --global alias.br branch | Create alias for branch |
git config --global alias.st status | Create alias for status |
git config --global alias.unstage 'reset HEAD --' | Alias for unstage |
git config --global alias.last 'log -1 HEAD' | Alias for last commit |
git config --global alias.tree 'log --graph --oneline --all' | Alias for tree view |
git config --global color.ui auto | Enable colors |
git config --global pull.rebase false | Set pull behavior |
git config --global rebase.autoStash true | Auto stash on rebase |
git config --global credential.helper cache | Cache credentials |
git config --global credential.helper 'cache --timeout=3600' | Cache for 1 hour |
git config --global core.autocrlf true | Handle line endings (Windows) |
git config --global core.autocrlf input | Handle line endings (Mac/Linux) |
git config --global core.excludesfile ~/.gitignore_global | Global gitignore |
git config --global help.autocorrect 1 | Auto-correct typos |
SECTION 2: INITIALIZATION & SETUP
| Command | Description |
|---|---|
git init | Create empty repo |
git init <directory> | Create repo in specific dir |
git init --bare | Create bare repo (server) |
git init --template=<template-dir> | Use custom template |
git clone <url> | Clone repo |
git clone <url> <dir> | Clone to specific dir |
git clone --branch <branch> <url> | Clone specific branch |
git clone --depth 1 <url> | Shallow clone (no history) |
git clone --recursive <url> | Clone with submodules |
git clone --single-branch <url> | Clone only one branch |
git clone --filter=blob:none <url> | Partial clone |
git remote add origin <url> | Add remote |
git remote add upstream <url> | Add second remote |
git remote -v | List remotes |
git remote show origin | Show remote details |
git remote rename origin upstream | Rename remote |
git remote remove origin | Remove remote |
git remote set-url origin <new-url> | Change remote URL |
SECTION 3: BASIC FILE OPERATIONS
| Command | Description |
|---|---|
git add <file> | Stage specific file |
git add <file1> <file2> | Stage multiple files |
git add . | Stage all changes (new+modified) |
git add --all | Stage all including deletions |
git add -A | Same as –all |
git add -u | Stage modified+deleted only |
git add -p | Stage interactively (patch) |
git add -i | Interactive staging |
git add --dry-run | Preview what will be staged |
git add --ignore-removal | Ignore deleted files |
git rm <file> | Remove file + stage deletion |
git rm --cached <file> | Remove from Git but keep locally |
git rm -r <dir> | Remove directory |
git rm -f <file> | Force remove |
git mv <old> <new> | Move/rename file |
git mv -f <old> <new> | Force move |
git restore <file> | Unstage + restore file |
git restore --staged <file> | Unstage only |
git restore --source=HEAD <file> | Restore from HEAD |
git restore --source=<commit> <file> | Restore from specific commit |
SECTION 4: COMMITTING
| Command | Description |
|---|---|
git commit -m "message" | Commit with message |
git commit -a -m "message" | Add all + commit |
git commit --amend -m "new" | Amend last commit message |
git commit --amend --no-edit | Add changes to last commit |
git commit --amend --author="Name <email>" | Change author |
git commit --date="2024-01-01" | Set custom date |
git commit -m "title" -m "description" | Multi-line message |
git commit --allow-empty | Commit with no changes |
git commit --signoff | Add Signed-off-by |
git commit --verbose | Show diff in editor |
git commit --dry-run | Preview what will commit |
git commit --fixup=<commit> | Mark as fixup for rebase |
git commit --squash=<commit> | Mark as squash for rebase |
git commit --reset-author | Reset author to yourself |
SECTION 5: STATUS & INFORMATION
| Command | Description |
|---|---|
git status | Show working tree status |
git status -s | Short format |
git status -b | Show branch info |
git status --ignored | Show ignored files |
git status --porcelain | Machine-readable format |
git log | Show commit history |
git log --oneline | One line per commit |
git log --oneline --graph | With ASCII graph |
git log --oneline --all | All branches |
git log --oneline --decorate | Show refs |
git log -n 5 | Last 5 commits |
git log --since="2 days ago" | Since time |
git log --until="2024-01-01" | Until date |
git log --author="name" | Filter by author |
git log --grep="pattern" | Search commit messages |
git log --grep="pattern" -i | Case insensitive |
git log -- <file> | History of specific file |
git log -p | Show diffs |
git log --stat | Show stats |
git log --pretty=format:"%h - %an: %s" | Custom format |
git log --pretty=format:"%h %ad %s" --date=short | With date |
git log --branches --not --remotes | Local only commits |
git shortlog | Group by author |
git shortlog -sn | Count commits per author |
git shortlog -sne | With email |
git show <commit> | Show commit details |
git show <commit>:<file> | Show file from commit |
git show HEAD~3 | Show 3 commits back |
git show HEAD^ | Show parent commit |
git show HEAD^^ | Show grandparent |
git show HEAD~5 | Show 5 commits back |
git diff | Unstaged changes |
git diff --staged | Staged changes |
git diff HEAD | All changes vs last commit |
git diff <branch1> <branch2> | Between branches |
git diff <commit1> <commit2> | Between commits |
git diff --name-only | Only file names |
git diff --stat | Statistics only |
git diff --color-words | Word by word diff |
git diff --cached | Same as –staged |
git diff --summary | Summary of changes |
git diff --check | Check whitespace errors |
git diff -- <file> | Diff specific file |
git diff --no-index <file1> <file2> | Diff non-git files |
git ls-files | List tracked files |
git ls-files --others | Untracked files |
git ls-files --ignored | Ignored files |
git ls-files --stage | With mode info |
git ls-tree HEAD | List tree contents |
git ls-remote origin | List remote refs |
git count-objects | Count objects |
git count-objects -v | Verbose |
git rev-parse HEAD | Get current commit hash |
git rev-parse --abbrev-ref HEAD | Current branch name |
git describe | Describe commit |
git describe --tags | With tags |
git name-rev <hash> | Name a revision |
SECTION 6: BRANCHING
| Command | Description |
|---|---|
git branch | List local branches |
git branch -r | List remote branches |
git branch -a | List all branches |
git branch -v | Last commit on each |
git branch -vv | With upstream tracking |
git branch --merged | Branches merged into current |
git branch --no-merged | Branches not merged |
git branch --contains <commit> | Branches containing commit |
git branch <name> | Create branch |
git branch <name> <start-point> | Create from specific point |
git branch -m <old> <new> | Rename branch |
git branch -m <new> | Rename current branch |
git branch -M <new> | Force rename |
git branch -d <name> | Delete branch |
git branch -D <name> | Force delete |
git branch -dr <remote/branch> | Delete remote branch |
git branch --unset-upstream | Remove upstream tracking |
git branch --set-upstream-to=<remote>/<branch> | Set upstream |
git branch -u <remote>/<branch> | Set upstream (short) |
git branch --edit-description | Edit branch description |
git branch --show-current | Show current branch |
git branch --list "pattern*" | List matching pattern |
git branch --sort=-committerdate | Sort by date |
git branch --format='%(refname:short)' | Custom output format |
git switch <branch> | Switch branch |
git switch -c <branch> | Create + switch |
git switch -C <branch> | Force create + switch |
git switch --detach <commit> | Detached HEAD state |
git switch --discard-changes <branch> | Discard local changes |
git switch --merge <branch> | Merge changes when switching |
git checkout <branch> | Switch branch (old way) |
git checkout -b <branch> | Create + switch (old way) |
git checkout -B <branch> | Force create + switch |
git checkout --track <remote>/<branch> | Create tracking branch |
git checkout --orphan <branch> | Create branch without history |
SECTION 7: MERGING
| Command | Description |
|---|---|
git merge <branch> | Merge branch into current |
git merge --no-ff <branch> | No fast-forward |
git merge --ff-only <branch> | Fast-forward only |
git merge --squash <branch> | Squash commits |
git merge --abort | Abort merge |
git merge --continue | Continue after conflicts |
git merge --no-commit | Merge without commit |
git merge --edit | Edit merge message |
git merge --log | Add commit log to message |
git merge --stat | Show diffstat |
git merge --verify-signatures | Verify GPG signatures |
git merge --strategy=ours | Use ours strategy |
git merge --strategy=theirs | Use theirs strategy |
git merge --strategy-option=patience | Patience algorithm |
git merge --strategy-option=ignore-space-change | Ignore whitespace |
git merge-tree <base> <ours> <theirs> | Preview merge |
git merge-base <commit1> <commit2> | Find common ancestor |
git merge-base --all <commit1> <commit2> | All common ancestors |
git merge-base --fork-point <branch> | Fork point |
SECTION 8: REBASING
| Command | Description |
|---|---|
git rebase <branch> | Rebase current onto branch |
git rebase --onto <newbase> <upstream> | Rebase onto different base |
git rebase -i <branch> | Interactive rebase |
git rebase -i HEAD~5 | Rebase last 5 commits |
git rebase --continue | Continue after resolving |
git rebase --skip | Skip current patch |
git rebase --abort | Abort rebase |
git rebase --edit-todo | Edit todo list |
git rebase --show-current-patch | Show current patch |
git rebase --autosquash | Auto squash fixups |
git rebase --autostash | Auto stash changes |
git rebase --committer-date-is-author-date | Preserve dates |
git rebase --ignore-date | Use current date |
git rebase --preserve-merges | Preserve merges (deprecated) |
git rebase --rebase-merges | Rebase merges |
git rebase --root | Rebase all commits |
git rebase --fork-point | Use fork point |
git rebase --whitespace=fix | Fix whitespace |
git rebase --exec "command" | Run command after each commit |
SECTION 9: STASHING
| Command | Description |
|---|---|
git stash | Save uncommitted work |
git stash push | Same as stash |
git stash push -m "message" | Stash with message |
git stash push -u | Include untracked files |
git stash push -a | Include ignored files |
git stash push -- <file> | Stash specific file |
git stash list | List all stashes |
git stash show | Show stash changes |
git stash show -p | Show full diff |
git stash show stash@{1} | Show specific stash |
git stash pop | Apply + remove last stash |
git stash pop stash@{1} | Apply + remove specific |
git stash apply | Apply keep last stash |
git stash apply stash@{1} | Apply keep specific |
git stash drop | Remove last stash |
git stash drop stash@{1} | Remove specific |
git stash clear | Remove all stashes |
git stash branch <branch> | Create branch from stash |
git stash branch <branch> stash@{1} | Branch from specific |
git stash create | Create stash entry (low-level) |
git stash store | Store stash entry |
git stash --keep-index | Stash unstaged only |
git stash --include-untracked | Alias for -u |
git stash --all | Alias for -a |
SECTION 10: REMOTES & SYNCING
| Command | Description |
|---|---|
git remote | List remotes |
git remote -v | List with URLs |
git remote show <name> | Show remote info |
git remote add <name> <url> | Add remote |
git remote rename <old> <new> | Rename remote |
git remote remove <name> | Remove remote |
git remote set-url <name> <url> | Change URL |
git remote set-url --add <name> <url> | Add additional URL |
git remote set-url --delete <name> <url> | Delete URL |
git remote set-head <name> -a | Set remote HEAD |
git remote set-head <name> -d | Delete remote HEAD |
git remote prune <name> | Remove stale branches |
git remote update | Fetch all remotes |
git remote get-url <name> | Get remote URL |
git fetch | Fetch from default remote |
git fetch <remote> | Fetch from specific remote |
git fetch --all | Fetch all remotes |
git fetch --prune | Prune after fetch |
git fetch --tags | Fetch tags |
git fetch --no-tags | Don’t fetch tags |
git fetch --depth=1 | Shallow fetch |
git fetch --unshallow | Convert shallow to full |
git fetch origin <branch> | Fetch specific branch |
git fetch origin <branch>:<local> | Fetch and create local |
git pull | Fetch + merge |
git pull --rebase | Fetch + rebase |
git pull --ff-only | Fast-forward only |
git pull --no-ff | No fast-forward |
git pull --autostash | Auto stash before pull |
git pull --tags | Also fetch tags |
git pull --no-tags | Don’t fetch tags |
git pull --depth=1 | Shallow pull |
git pull --verify-signatures | Verify signatures |
git push | Push to default remote |
git push origin <branch> | Push branch |
git push origin <local>:<remote> | Push with different name |
git push -u origin <branch> | Set upstream |
git push --all | Push all branches |
git push --tags | Push tags |
git push --follow-tags | Push commits + tags |
git push --force | Force push |
git push --force-with-lease | Safer force push |
git push --force-if-includes | Force if includes |
git push --delete origin <branch> | Delete remote branch |
git push origin :<branch> | Delete remote (alternative) |
git push --prune | Remove remote branches |
git push --mirror | Mirror push |
git push --dry-run | Preview push |
git push --set-upstream | Same as -u |
git push --no-verify | Skip pre-push hooks |
git push --receive-pack=<git-receive-pack> | Custom receive pack |
git push --exec=<receive-pack> | Same as above |
SECTION 11: UNDOING & RESETTING
| Command | Description |
|---|---|
git reset <file> | Unstage file |
git reset | Unstage all |
git reset --soft HEAD~1 | Undo commit (keep changes staged) |
git reset --mixed HEAD~1 | Undo commit (keep changes unstaged) |
git reset --hard HEAD~1 | Undo commit (delete changes) |
git reset --hard HEAD | Discard all unstaged changes |
git reset --hard <commit> | Reset to specific commit |
git reset --soft <commit> | Reset but keep changes staged |
git reset --mixed <commit> | Reset but keep changes unstaged |
git reset --keep <commit> | Reset if safe |
git reset --merge | Reset with merge |
git reset --patch | Interactive reset |
git checkout -- <file> | Discard file changes |
git checkout HEAD -- <file> | Restore from HEAD |
git checkout <commit> -- <file> | Restore from commit |
git checkout -- . | Discard all changes |
git restore <file> | Restore file (new way) |
git restore --staged <file> | Unstage (new way) |
git restore --source=HEAD --staged --worktree <file> | Full restore |
git restore --source=<commit> <file> | Restore from commit |
git revert <commit> | Create inverse commit |
git revert HEAD~3..HEAD | Revert range |
git revert --no-commit <commit> | Revert without committing |
git revert --continue | Continue revert |
git revert --abort | Abort revert |
git revert --edit | Edit revert message |
git revert -n | Same as –no-commit |
git clean | Remove untracked files |
git clean -n | Dry run |
git clean -f | Force remove |
git clean -fd | Remove directories too |
git clean -fx | Remove ignored files too |
git clean -fX | Remove only ignored |
git clean -i | Interactive clean |
git rm --cached <file> | Stop tracking (keep file) |
git rm -r --cached <dir> | Stop tracking directory |
git update-index --assume-unchanged <file> | Ignore local changes |
git update-index --no-assume-unchanged <file> | Revert above |
git update-index --skip-worktree <file> | Skip worktree |
git update-index --no-skip-worktree <file> | Revert above |
SECTION 12: TAGGING
| Command | Description |
|---|---|
git tag | List tags |
git tag -l "v1.*" | List matching pattern |
git tag -n | List tags with messages |
git tag <name> | Create lightweight tag |
git tag -a <name> -m "message" | Create annotated tag |
git tag -a <name> <commit> | Tag specific commit |
git tag -s <name> -m "message" | GPG signed tag |
git tag -d <name> | Delete tag |
git tag --delete <name> | Same as above |
git push origin <tag> | Push single tag |
git push origin --tags | Push all tags |
git push origin --follow-tags | Push commits + tags |
git push origin :refs/tags/<tag> | Delete remote tag |
git push --delete origin <tag> | Delete remote tag |
git fetch --tags | Fetch tags |
git pull --tags | Pull tags |
git tag --contains <commit> | Tags containing commit |
git tag --merged <branch> | Tags merged into branch |
git tag --points-at <commit> | Tags pointing at commit |
git show <tag> | Show tag details |
git verify-tag <tag> | Verify GPG signature |
git tag --list --format='%(refname:short)' | Custom format |
SECTION 13: DIFF & COMPARE
| Command | Description |
|---|---|
git diff | Unstaged changes |
git diff --staged | Staged changes |
git diff HEAD | All vs last commit |
git diff <commit> | Changes since commit |
git diff <commit1> <commit2> | Between commits |
git diff <branch1> <branch2> | Between branches |
git diff <branch1>..<branch2> | Same as above |
git diff <branch1>...<branch2> | Diff from common ancestor |
git diff --cached | Same as –staged |
git diff --name-only | Only file names |
git diff --name-status | Status + names |
git diff --stat | Statistics |
git diff --shortstat | Short statistics |
git diff --numstat | Numeric statistics |
git diff --summary | Summary |
git diff --check | Check whitespace |
git diff --color-words | Word diff |
git diff --word-diff | Word diff alternative |
git diff --patience | Patience algorithm |
git diff --histogram | Histogram algorithm |
git diff --minimal | Minimal diff |
git diff --ignore-space-at-eol | Ignore EOL whitespace |
git diff --ignore-cr-at-eol | Ignore CR at EOL |
git diff --ignore-blank-lines | Ignore blank lines |
git diff --ignore-all-space | Ignore all whitespace |
git diff --ignore-space-change | Ignore whitespace changes |
git diff --exit-code | Exit 1 if differences |
git diff --quiet | No output, just exit code |
git diff --no-index <file1> <file2> | Compare non-git files |
git diff -- <file> | Specific file |
git diff -- . ':(exclude)*.log' | Exclude pattern |
git diff --relative | Relative paths |
git diff --patience -- <file> | Combine options |
git diff-tree <commit> | Show tree diff |
git diff-files | Compare with index |
git diff-index <tree> | Compare with tree |
SECTION 14: CHERRY-PICK & REBASE
| Command | Description |
|---|---|
git cherry-pick <commit> | Apply commit to current branch |
git cherry-pick <commit1> <commit2> | Multiple commits |
git cherry-pick <commit1>..<commit2> | Range of commits |
git cherry-pick --continue | Continue after conflict |
git cherry-pick --abort | Abort cherry-pick |
git cherry-pick --quit | Quit but leave changes |
git cherry-pick --no-commit | Apply without committing |
git cherry-pick --edit | Edit commit message |
git cherry-pick --signoff | Add Signed-off-by |
git cherry-pick --keep-redundant-commits | Keep duplicates |
git cherry-pick --strategy=recursive -X theirs | Use theirs on conflict |
git cherry-pick --strategy=recursive -X ours | Use ours on conflict |
git cherry | Find commits not yet applied |
git cherry -v | Verbose |
git cherry <upstream> <head> | Compare branches |
git cherry <upstream> | Compare with current |
git format-patch -1 <commit> | Create patch file |
git format-patch <commit1>..<commit2> | Create patch series |
git apply <patch> | Apply patch |
git apply --check <patch> | Check if patch applies |
git apply --reject <patch> | Apply with rejects |
git apply --3way | 3-way merge if needed |
git am <patch> | Apply mail patches |
git am --continue | Continue after conflict |
git am --abort | Abort |
git am --skip | Skip current patch |
git am --resolved | Mark resolved |
git am -3 | 3-way merge |
git am --signoff | Add signoff |
git am --keep-cr | Keep carriage returns |
SECTION 15: BISECT (BUG FINDING)
| Command | Description |
|---|---|
git bisect start | Start bisect session |
git bisect start <bad> <good> | Start with known bad/good |
git bisect bad | Mark current as bad |
git bisect bad <commit> | Mark commit as bad |
git bisect good <commit> | Mark commit as good |
git bisect reset | End bisect session |
git bisect replay <log> | Replay previous bisect |
git bisect log | Show bisect log |
git bisect run <script> | Auto bisect with script |
git bisect skip | Skip current commit |
git bisect visualize | Visualize with gitk |
git bisect terms | Show terms |
git bisect terms --term-bad=broken --term-good=working | Custom terms |
git bisect next | Move to next commit (low-level) |
SECTION 16: SUBMODULES
| Command | Description |
|---|---|
git submodule add <url> | Add submodule |
git submodule add <url> <path> | Add to specific path |
git submodule add --branch <branch> <url> | Add with specific branch |
git submodule add --name <name> <url> | Custom name |
git submodule init | Initialize submodules |
git submodule update | Update submodules |
git submodule update --remote | Update to remote |
git submodule update --init | Init + update |
git submodule update --recursive | Update nested |
git submodule update --checkout | Checkout commit |
git submodule update --rebase | Rebase submodule |
git submodule update --merge | Merge submodule |
git submodule status | Show submodule status |
git submodule foreach <command> | Run command in each |
git submodule foreach --recursive <command> | Run recursively |
git submodule sync | Sync URLs |
git submodule sync --recursive | Sync recursively |
git submodule deinit <path> | Unregister submodule |
git submodule deinit --all | Unregister all |
git submodule set-url <path> <new-url> | Change URL |
git submodule absorbgitdirs | Move gitdirs to superproject |
git clone --recursive <url> | Clone with submodules |
git clone --recurse-submodules <url> | Same as above |
git pull --recurse-submodules | Pull with submodules |
git push --recurse-submodules=check | Check submodules on push |
git push --recurse-submodules=on-demand | Push submodules too |
SECTION 17: GITHUB SPECIFIC (gh CLI)
| Command | Description |
|---|---|
gh auth login | Login to GitHub |
gh auth status | Check auth status |
gh auth logout | Logout |
gh auth refresh | Refresh token |
gh repo create <name> | Create repository |
gh repo create <name> --public | Public repo |
gh repo create <name> --private | Private repo |
gh repo create <name> --clone | Clone after create |
gh repo create <name> --push | Push after create |
gh repo create <name> --template <template> | From template |
gh repo clone <repo> | Clone repository |
gh repo fork | Fork current repo |
gh repo fork --clone | Fork + clone |
gh repo view | View repo info |
gh repo view --web | Open in browser |
gh repo list | List your repos |
gh repo list <user> | List user’s repos |
gh repo delete | Delete repository |
gh repo archive | Archive repo |
gh repo unarchive | Unarchive |
gh repo rename <new-name> | Rename repo |
gh repo sync | Sync fork with upstream |
gh repo set-default | Set default repo |
gh pr create | Create pull request |
gh pr create --title "title" --body "body" | With title+body |
gh pr create --draft | Draft PR |
gh pr create --fill | Auto fill from commits |
gh pr create --base <branch> | Set base branch |
gh pr create --head <branch> | Set head branch |
gh pr create --assignee @me | Assign yourself |
gh pr create --reviewer <user> | Request review |
gh pr create --label <label> | Add labels |
gh pr create --milestone <name> | Set milestone |
gh pr create --project <name> | Add to project |
gh pr list | List PRs |
gh pr list --state open | Open PRs |
gh pr list --state closed | Closed PRs |
gh pr list --state merged | Merged PRs |
gh pr list --author <user> | Filter by author |
gh pr list --assignee <user> | Filter by assignee |
gh pr list --reviewer <user> | Filter by reviewer |
gh pr list --label <label> | Filter by label |
gh pr list --base <branch> | Filter by base |
gh pr list --head <branch> | Filter by head |
gh pr list --limit 10 | Limit results |
gh pr view | View current PR |
gh pr view <number> | View specific PR |
gh pr view --web | Open in browser |
gh pr checkout <number> | Checkout PR locally |
gh pr diff | Show PR diff |
gh pr diff <number> | Show specific PR diff |
gh pr merge | Merge current PR |
gh pr merge --merge | Merge commit |
gh pr merge --squash | Squash merge |
gh pr merge --rebase | Rebase merge |
gh pr merge --delete-branch | Delete branch after merge |
gh pr merge --auto | Auto merge when ready |
gh pr review | Review current PR |
gh pr review --comment -b "message" | Comment |
gh pr review --approve | Approve |
gh pr review --request-changes | Request changes |
gh pr comment <number> -b "message" | Add comment |
gh pr comment --editor | Use editor |
gh pr status | Show PR status |
gh pr ready <number> | Mark draft as ready |
gh pr close <number> | Close PR |
gh pr reopen <number> | Reopen PR |
gh issue create | Create issue |
gh issue create --title "title" --body "body" | With title+body |
gh issue create --assignee @me | Assign yourself |
gh issue create --label <label> | Add labels |
gh issue create --project <name> | Add to project |
gh issue create --milestone <name> | Set milestone |
gh issue list | List issues |
gh issue list --state open | Open issues |
gh issue list --state closed | Closed issues |
gh issue list --author <user> | Filter by author |
gh issue list --assignee <user> | Filter by assignee |
gh issue list --label <label> | Filter by label |
gh issue list --limit 10 | Limit results |
gh issue view <number> | View issue |
gh issue view --web | Open in browser |
gh issue comment <number> -b "message" | Add comment |
gh issue close <number> | Close issue |
gh issue reopen <number> | Reopen issue |
gh issue transfer <number> <repo> | Transfer issue |
gh issue lock <number> | Lock issue |
gh issue unlock <number> | Unlock issue |
gh issue pin <number> | Pin issue |
gh issue unpin <number> | Unpin issue |
gh gist list | List gists |
gh gist list --public | Public gists |
gh gist list --secret | Secret gists |
gh gist create <file> | Create gist |
gh gist create <file> --public | Public gist |
gh gist create <file> --desc "description" | With description |
gh gist view <id> | View gist |
gh gist view --web | Open in browser |
gh gist clone <id> | Clone gist |
gh gist edit <id> <file> | Edit gist |
gh gist delete <id> | Delete gist |
gh alias list | List aliases |
gh alias set <name> <command> | Create alias |
gh alias delete <name> | Delete alias |
gh alias import -f <file> | Import aliases |
gh alias export | Export aliases |
gh config set <key> <value> | Set config |
gh config get <key> | Get config |
gh config list | List config |
gh api <endpoint> | Call GitHub API |
gh api --method POST <endpoint> -f key=value | POST request |
gh api --paginate | Paginate results |
gh api --silent | No output |
gh api --template '{{.name}}' | Template output |
gh search repos <query> | Search repositories |
gh search issues <query> | Search issues |
gh search prs <query> | Search PRs |
gh search code <query> | Search code |
gh search commits <query> | Search commits |
gh search topics <query> | Search topics |
gh extension list | List extensions |
gh extension install <repo> | Install extension |
gh extension upgrade <name> | Upgrade extension |
gh extension upgrade --all | Upgrade all |
gh extension remove <name> | Remove extension |
gh extension create <name> | Create extension |
gh release list | List releases |
gh release create <tag> | Create release |
gh release create <tag> --title "title" | With title |
gh release create <tag> --notes "notes" | With notes |
gh release create <tag> --draft | Draft release |
gh release create <tag> --prerelease | Pre-release |
gh release create <tag> --target <branch> | Set target |
gh release create <tag> <file> | Attach file |
gh release view <tag> | View release |
gh release download <tag> | Download assets |
gh release delete <tag> | Delete release |
gh workflow list | List workflows |
gh workflow list --all | All workflows |
gh workflow view <id> | View workflow |
gh workflow run <id> | Run workflow |
gh workflow run <id> -f key=value | With inputs |
gh workflow enable <id> | Enable workflow |
gh workflow disable <id> | Disable workflow |
gh run list | List runs |
gh run list --workflow <id> | Filter by workflow |
gh run view <id> | View run |
gh run view <id> --log | View logs |
gh run watch <id> | Watch run |
gh run rerun <id> | Rerun run |
gh run cancel <id> | Cancel run |
gh run delete <id> | Delete run |
gh codespace list | List codespaces |
gh codespace create | Create codespace |
gh codespace create --repo <repo> | For specific repo |
gh codespace create --branch <branch> | Specific branch |
gh codespace ssh <name> | SSH into codespace |
gh codespace code <name> | Open in VS Code |
gh codespace stop <name> | Stop codespace |
gh codespace delete <name> | Delete codespace |
gh codespace ports | List forwarded ports |
gh codespace ports visibility <port> public | Make port public |
gh secret list | List secrets |
gh secret set <name> | Set secret |
gh secret set <name> -b <value> | Set from clipboard |
gh secret set <name> <file | Set from file |
gh secret remove <name> | Remove secret |
gh secret list --org <org> | Org secrets |
gh variable list | List variables |
gh variable set <name> | Set variable |
gh variable set <name> -b <value> | Set value |
gh variable remove <name> | Remove variable |
gh label list | List labels |
gh label create <name> -c <color> | Create label |
gh label edit <name> --new-name <new> | Edit label |
gh label delete <name> | Delete label |
gh label clone <repo> | Clone labels from repo |
gh milestone list | List milestones |
gh milestone create <title> | Create milestone |
gh milestone create --due-date <date> | With due date |
gh milestone delete <number> | Delete milestone |
gh project list | List projects |
gh project view <number> | View project |
gh project create <title> | Create project |
gh project delete <number> | Delete project |
gh project item-add <number> --url <url> | Add item |
gh project item-delete <number> | Delete item |
gh project field-create <number> --name <name> --type <type> | Create field |
gh project field-delete <number> | Delete field |
SECTION 18: GIT HOOKS (Common Hook Names)
| Hook Name | Trigger |
|---|---|
pre-commit | Before commit |
prepare-commit-msg | Before commit message editor |
commit-msg | After message is written |
post-commit | After commit completes |
pre-rebase | Before rebase |
post-checkout | After checkout |
post-merge | After merge |
pre-push | Before push |
pre-receive | Server before receive |
update | Server per branch |
post-receive | Server after receive |
post-update | Server after update |
pre-auto-gc | Before garbage collection |
post-rewrite | After rewrite (rebase/amend) |
applypatch-msg | Before applying patch |
pre-applypatch | Before applying patch |
post-applypatch | After applying patch |
sendemail-validate | Before sending email |
fsmonitor-watchman | Watchman integration |
p4-pre-submit | Perforce before submit |
post-index-change | After index changes |
SECTION 19: .GITIGNORE PATTERNS
| Pattern | Matches |
|---|---|
*.log | All .log files |
temp/ | Directory named temp |
/temp | temp in root only |
temp | Any file/dir named temp |
!keep.log | Except keep.log |
*.tmp | All .tmp files |
*.swp | Vim swap files |
.*.swp | Vim swap (hidden) |
node_modules/ | Node modules |
vendor/ | Go/PHP vendor |
__pycache__/ | Python cache |
*.pyc | Python compiled |
.env | Environment file |
.env.* | Environment files |
.DS_Store | Mac metadata |
Thumbs.db | Windows thumbnails |
dist/ | Build output |
build/ | Build output |
target/ | Rust/Java build |
bin/ | Binaries |
obj/ | Object files |
*.exe | Windows executables |
*.dll | Dynamic libraries |
*.so | Shared objects |
*.dylib | Mac libraries |
*.o | Object files |
coverage/ | Test coverage |
.coverage | Coverage file |
*.log | Logs |
*.pid | Process IDs |
*.seed | Seed files |
*.sock | Sockets |
*.lock | Lock files |
.vscode/ | VS Code settings |
.idea/ | IntelliJ settings |
*.iml | IntelliJ module |
.project | Eclipse project |
.classpath | Eclipse classpath |
.settings/ | Eclipse settings |
.vs/ | Visual Studio |
*.suo | Visual Studio |
*.user | Visual Studio |
*.sln.docstates | Visual Studio |
npm-debug.log* | NPM logs |
yarn-debug.log* | Yarn logs |
yarn-error.log* | Yarn errors |
package-lock.json | NPM lock (sometimes) |
yarn.lock | Yarn lock (sometimes) |
pnpm-lock.yaml | PNPM lock |
.terraform/ | Terraform |
*.tfstate | Terraform state |
*.tfstate.* | Terraform state |
*.tfvars | Terraform vars |
.serverless/ | Serverless framework |
.serverless_plugins/ | Serverless plugins |
*.zip | Archives |
*.tar | Archives |
*.gz | Archives |
*.rar | Archives |
*.7z | Archives |
.env.local | Local env |
.env.*.local | Local env files |
*.key | Private keys |
*.pem | Certificates |
*.crt | Certificates |
*.p12 | PKCS12 |
*.pfx | PFX certificates |
secrets/ | Secrets directory |
credentials/ | Credentials |
.secrets | Secrets file |
.vault | Vault secrets |
SECTION 20: GIT ALIASES (Common Setups)
| Alias | Command |
|---|---|
git co | checkout |
git cob | checkout -b |
git br | branch |
git st | status -sb |
git ci | commit -v |
git cia | commit -a -v |
git cam | commit -am |
git amend | commit --amend -C HEAD |
git lg | log --graph --oneline --decorate --all |
git lgg | log --graph --oneline --decorate |
git hist | log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short |
git unstage | reset HEAD -- |
git last | log -1 HEAD |
git diffc | diff --cached |
git ds | diff --staged |
git dh | diff HEAD |
git incoming | log origin/main..HEAD --oneline |
git outgoing | log HEAD..origin/main --oneline |
git who | shortlog -sne |
git ignore | update-index --assume-unchanged |
git unignore | update-index --no-assume-unchanged |
git tracked | ls-tree --full-tree -r HEAD |
git untracked | ls-files --others --exclude-standard |
git tags | tag -ln |
git graph | log --graph --oneline --all --decorate --simplify-by-decoration |
git tree | log --graph --pretty=oneline --abbrev-commit --all |
git fixup | commit --fixup |
git squash | commit --squash |
git root | rev-parse --show-toplevel |
git cleanup | !git branch --merged | grep -v '\\*\\|main\\|master' | xargs -n 1 git branch -d |
git fresh | !git reset --hard HEAD && git clean -fd |
git undo | reset --soft HEAD^ |
git redo | reset --soft HEAD@{1} |
git wip | !git add -A && git commit -m "WIP" |
git unwip | !git log -1 --grep=WIP | grep -q WIP && git reset HEAD^ |
git pr | !gh pr create --fill |
git browse | !gh repo view --web |
SECTION 21: ERROR CODES & MEANINGS
| Error Code | Meaning |
|---|---|
1 | General error |
128 | Invalid arguments/usage |
129 | Usage error |
130 | Merge conflict |
137 | Out of memory |
139 | Segmentation fault |
255 | Git internal error |
SECTION 22: ENVIRONMENT VARIABLES
| Variable | Purpose |
|---|---|
GIT_AUTHOR_NAME | Override author name |
GIT_AUTHOR_EMAIL | Override author email |
GIT_AUTHOR_DATE | Override author date |
GIT_COMMITTER_NAME | Override committer name |
GIT_COMMITTER_EMAIL | Override committer email |
GIT_COMMITTER_DATE | Override committer date |
GIT_EDITOR | Set editor |
GIT_PAGER | Set pager |
GIT_SSH | SSH command |
GIT_SSH_COMMAND | SSH command with options |
GIT_ASKPASS | Askpass program |
GIT_DIR | .git directory path |
GIT_WORK_TREE | Work tree path |
GIT_INDEX_FILE | Index file path |
GIT_OBJECT_DIRECTORY | Objects directory |
GIT_ALTERNATE_OBJECT_DIRECTORIES | Alternate object locations |
GIT_HTTP_PROXY | HTTP proxy |
GIT_HTTPS_PROXY | HTTPS proxy |
GIT_NO_PROXY | No proxy domains |
GIT_CONFIG_GLOBAL | Global config path |
GIT_CONFIG_SYSTEM | System config path |
GIT_FLUSH | Flush output |
GIT_TRACE | Trace output |
GIT_TRACE_PACKET | Packet trace |
GIT_TRACE_PERFORMANCE | Performance trace |
GIT_TRACE_SETUP | Setup trace |
GIT_MERGE_VERBOSITY | Merge verbosity |
GIT_CEILING_DIRECTORIES | Ceiling directories |
GIT_DISCOVERY_ACROSS_FILESYSTEM | Cross FS discovery |
GIT_OPTIONAL_LOCKS | Optional locks |
GIT_PAGER_IN_USE | Pager active |
GIT_SEQUENCE_EDITOR | Rebase todo editor |
GIT_SKIP_TESTS | Skip tests |
GIT_TERMINAL_PROMPT | Terminal prompts |
GIT_CLONE_PROTECTION_ACTIVE | Clone protection |
GIT_PROTOCOL | Protocol version |
GIT_NAMESPACE | Namespace |
GIT_REFLOG_ACTION | Reflog action |
GIT_REF_PARANOIA | Paranoid ref checks |
SECTION 23: COMMIT MESSAGE CONVENTIONS (Conventional Commits)
| Type | Description |
|---|---|
feat: | New feature |
fix: | Bug fix |
docs: | Documentation |
style: | Code style (formatting) |
refactor: | Code change that neither fixes bug nor adds feature |
perf: | Performance improvement |
test: | Adding/updating tests |
build: | Build system or dependencies |
ci: | CI configuration |
chore: | Other changes |
revert: | Revert previous commit |
BREAKING CHANGE: | Breaking API change |
SECTION 24: SEMANTIC VERSIONING (Tags)
| Version | Meaning |
|---|---|
v1.0.0 | Major.Minor.Patch |
Major | Breaking changes |
Minor | New features (backward compatible) |
Patch | Bug fixes |
v1.0.0-alpha | Alpha pre-release |
v1.0.0-beta | Beta pre-release |
v1.0.0-rc.1 | Release candidate |
SECTION 25: GIT REFERENCE SHORTCUTS
| Shortcut | Meaning |
|---|---|
HEAD | Current commit |
HEAD^ | Parent of HEAD |
HEAD^^ | Grandparent |
HEAD~1 | 1 commit back |
HEAD~5 | 5 commits back |
HEAD^2 | Second parent (merge) |
HEAD~3^2 | 3 back, then second parent |
HEAD@{0} | Current position |
HEAD@{1} | Previous position |
HEAD@{5.minutes.ago} | Position 5 minutes ago |
main~3 | 3 commits before main |
main..feature | Commits in feature not in main |
main...feature | Commits in either but not both |
feature^@ | All parents of feature |
feature^! | Feature commit without parents |
:/(fix bug) | Commit with message containing “fix bug” |
@{u} | Upstream of current branch |
@{push} | Push destination |
[tag]^{commit} | Dereference tag to commit |
[tree]:[path] | File in tree |