Master Computer Science The Smart Way

Complete GitHub Reference Guide: From Git Basics to gh CLI Mastery

Complete GitHub Reference Guide: From Git Basics to gh CLI Mastery
0

BASIC COMMANDS

CommandDescription
git initCreate new repository
git clone <url>Copy existing repo
git statusCheck what changed
git add <file>Stage a file
git add .Stage all files
git commit -m "msg"Save snapshot
git log --onelineView commit history
git diffSee unstaged changes

BRANCHING

CommandDescription
git branchList 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

CommandDescription
git remote add origin <url>Link to GitHub
git push -u origin mainFirst push
git pushUpload commits
git pullDownload + merge
git fetchDownload only

UNDO CHANGES

CommandDescription
git reset <file>Unstage a file
git reset --soft HEAD~1Undo commit (keep changes)
git reset --hard HEAD~1Undo commit (delete changes)
git checkout -- <file>Discard file changes
git commit --amend -m "new"Rewrite last message

GITHUB CLI (gh)

CommandDescription
gh auth loginLogin to GitHub
gh repo create <name>Create repository
gh pr createCreate pull request
gh pr checkout <#>Checkout PR locally
gh issue listView open issues
gh issue createCreate new issue

COMMON ERRORS

ErrorSolution
fatal: not a git repositoryRun git init or git clone
rejected (non-fast-forward)Run git pull then git push
detached HEADRun git switch <branch>
Merge conflictsEdit files → git add → git commit

.GITIGNORE ENTRIES

EntryIgnores
node_modules/Node packages
.envEnvironment variables
.DS_StoreMac system files
dist/Build output
*.logLog files
coverage/Test coverage

STASHING

CommandDescription
git stashSave uncommitted work
git stash listView stashes
git stash popApply + remove stash
git stash applyApply keep stash
git stash dropDelete stash

TAGS

CommandDescription
git tag v1.0Create tag
git tagList all tags
git push origin v1.0Push tag to GitHub
git push --tagsPush all tags
git tag -d v1.0Delete local tag

USEFUL ALIASES

Alias CommandShortcut For
git config --global alias.co checkoutgit co
git config --global alias.br branchgit br
git config --global alias.st statusgit st
git config --global alias.unstage 'reset HEAD --'git unstage
git config --global alias.last 'log -1 HEAD'git last

VIEWING HISTORY

CommandDescription
git log --oneline --graphPretty 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

StepCommand/Action
1git checkout -b feature
2Make changes to code
3git add .
4git commit -m "message"
5git push origin feature
6Open GitHub → Click “Compare & pull request”
7Request review
8Merge after approval

MARKDOWN FOR README

SyntaxResult
# TitleH1 heading
## SubtitleH2 heading
**bold**bold
*italic*italic
- itembullet point
1. itemnumbered list
[text](url)hyperlink
`code`inline code
```code block```code block

1000

GITHUB CHEATSHEET (1000+ Rows – Complete Reference)

SECTION 1: GIT CONFIGURATION

CommandDescription
git config --global user.name "Name"Set username
git config --global user.email "email"Set email
git config --global --listList all config
git config --global core.editor "code --wait"Set VS Code as editor
git config --global init.defaultBranch mainSet default branch name
git config --global alias.co checkoutCreate alias for checkout
git config --global alias.br branchCreate alias for branch
git config --global alias.st statusCreate 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 autoEnable colors
git config --global pull.rebase falseSet pull behavior
git config --global rebase.autoStash trueAuto stash on rebase
git config --global credential.helper cacheCache credentials
git config --global credential.helper 'cache --timeout=3600'Cache for 1 hour
git config --global core.autocrlf trueHandle line endings (Windows)
git config --global core.autocrlf inputHandle line endings (Mac/Linux)
git config --global core.excludesfile ~/.gitignore_globalGlobal gitignore
git config --global help.autocorrect 1Auto-correct typos

SECTION 2: INITIALIZATION & SETUP

CommandDescription
git initCreate empty repo
git init <directory>Create repo in specific dir
git init --bareCreate 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 -vList remotes
git remote show originShow remote details
git remote rename origin upstreamRename remote
git remote remove originRemove remote
git remote set-url origin <new-url>Change remote URL

SECTION 3: BASIC FILE OPERATIONS

CommandDescription
git add <file>Stage specific file
git add <file1> <file2>Stage multiple files
git add .Stage all changes (new+modified)
git add --allStage all including deletions
git add -ASame as –all
git add -uStage modified+deleted only
git add -pStage interactively (patch)
git add -iInteractive staging
git add --dry-runPreview what will be staged
git add --ignore-removalIgnore 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

CommandDescription
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-editAdd 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-emptyCommit with no changes
git commit --signoffAdd Signed-off-by
git commit --verboseShow diff in editor
git commit --dry-runPreview what will commit
git commit --fixup=<commit>Mark as fixup for rebase
git commit --squash=<commit>Mark as squash for rebase
git commit --reset-authorReset author to yourself

SECTION 5: STATUS & INFORMATION

CommandDescription
git statusShow working tree status
git status -sShort format
git status -bShow branch info
git status --ignoredShow ignored files
git status --porcelainMachine-readable format
git logShow commit history
git log --onelineOne line per commit
git log --oneline --graphWith ASCII graph
git log --oneline --allAll branches
git log --oneline --decorateShow refs
git log -n 5Last 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" -iCase insensitive
git log -- <file>History of specific file
git log -pShow diffs
git log --statShow stats
git log --pretty=format:"%h - %an: %s"Custom format
git log --pretty=format:"%h %ad %s" --date=shortWith date
git log --branches --not --remotesLocal only commits
git shortlogGroup by author
git shortlog -snCount commits per author
git shortlog -sneWith email
git show <commit>Show commit details
git show <commit>:<file>Show file from commit
git show HEAD~3Show 3 commits back
git show HEAD^Show parent commit
git show HEAD^^Show grandparent
git show HEAD~5Show 5 commits back
git diffUnstaged changes
git diff --stagedStaged changes
git diff HEADAll changes vs last commit
git diff <branch1> <branch2>Between branches
git diff <commit1> <commit2>Between commits
git diff --name-onlyOnly file names
git diff --statStatistics only
git diff --color-wordsWord by word diff
git diff --cachedSame as –staged
git diff --summarySummary of changes
git diff --checkCheck whitespace errors
git diff -- <file>Diff specific file
git diff --no-index <file1> <file2>Diff non-git files
git ls-filesList tracked files
git ls-files --othersUntracked files
git ls-files --ignoredIgnored files
git ls-files --stageWith mode info
git ls-tree HEADList tree contents
git ls-remote originList remote refs
git count-objectsCount objects
git count-objects -vVerbose
git rev-parse HEADGet current commit hash
git rev-parse --abbrev-ref HEADCurrent branch name
git describeDescribe commit
git describe --tagsWith tags
git name-rev <hash>Name a revision

SECTION 6: BRANCHING

CommandDescription
git branchList local branches
git branch -rList remote branches
git branch -aList all branches
git branch -vLast commit on each
git branch -vvWith upstream tracking
git branch --mergedBranches merged into current
git branch --no-mergedBranches 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-upstreamRemove upstream tracking
git branch --set-upstream-to=<remote>/<branch>Set upstream
git branch -u <remote>/<branch>Set upstream (short)
git branch --edit-descriptionEdit branch description
git branch --show-currentShow current branch
git branch --list "pattern*"List matching pattern
git branch --sort=-committerdateSort 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

CommandDescription
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 --abortAbort merge
git merge --continueContinue after conflicts
git merge --no-commitMerge without commit
git merge --editEdit merge message
git merge --logAdd commit log to message
git merge --statShow diffstat
git merge --verify-signaturesVerify GPG signatures
git merge --strategy=oursUse ours strategy
git merge --strategy=theirsUse theirs strategy
git merge --strategy-option=patiencePatience algorithm
git merge --strategy-option=ignore-space-changeIgnore 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

CommandDescription
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~5Rebase last 5 commits
git rebase --continueContinue after resolving
git rebase --skipSkip current patch
git rebase --abortAbort rebase
git rebase --edit-todoEdit todo list
git rebase --show-current-patchShow current patch
git rebase --autosquashAuto squash fixups
git rebase --autostashAuto stash changes
git rebase --committer-date-is-author-datePreserve dates
git rebase --ignore-dateUse current date
git rebase --preserve-mergesPreserve merges (deprecated)
git rebase --rebase-mergesRebase merges
git rebase --rootRebase all commits
git rebase --fork-pointUse fork point
git rebase --whitespace=fixFix whitespace
git rebase --exec "command"Run command after each commit

SECTION 9: STASHING

CommandDescription
git stashSave uncommitted work
git stash pushSame as stash
git stash push -m "message"Stash with message
git stash push -uInclude untracked files
git stash push -aInclude ignored files
git stash push -- <file>Stash specific file
git stash listList all stashes
git stash showShow stash changes
git stash show -pShow full diff
git stash show stash@{1}Show specific stash
git stash popApply + remove last stash
git stash pop stash@{1}Apply + remove specific
git stash applyApply keep last stash
git stash apply stash@{1}Apply keep specific
git stash dropRemove last stash
git stash drop stash@{1}Remove specific
git stash clearRemove all stashes
git stash branch <branch>Create branch from stash
git stash branch <branch> stash@{1}Branch from specific
git stash createCreate stash entry (low-level)
git stash storeStore stash entry
git stash --keep-indexStash unstaged only
git stash --include-untrackedAlias for -u
git stash --allAlias for -a

SECTION 10: REMOTES & SYNCING

CommandDescription
git remoteList remotes
git remote -vList 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> -aSet remote HEAD
git remote set-head <name> -dDelete remote HEAD
git remote prune <name>Remove stale branches
git remote updateFetch all remotes
git remote get-url <name>Get remote URL
git fetchFetch from default remote
git fetch <remote>Fetch from specific remote
git fetch --allFetch all remotes
git fetch --prunePrune after fetch
git fetch --tagsFetch tags
git fetch --no-tagsDon’t fetch tags
git fetch --depth=1Shallow fetch
git fetch --unshallowConvert shallow to full
git fetch origin <branch>Fetch specific branch
git fetch origin <branch>:<local>Fetch and create local
git pullFetch + merge
git pull --rebaseFetch + rebase
git pull --ff-onlyFast-forward only
git pull --no-ffNo fast-forward
git pull --autostashAuto stash before pull
git pull --tagsAlso fetch tags
git pull --no-tagsDon’t fetch tags
git pull --depth=1Shallow pull
git pull --verify-signaturesVerify signatures
git pushPush 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 --allPush all branches
git push --tagsPush tags
git push --follow-tagsPush commits + tags
git push --forceForce push
git push --force-with-leaseSafer force push
git push --force-if-includesForce if includes
git push --delete origin <branch>Delete remote branch
git push origin :<branch>Delete remote (alternative)
git push --pruneRemove remote branches
git push --mirrorMirror push
git push --dry-runPreview push
git push --set-upstreamSame as -u
git push --no-verifySkip 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

CommandDescription
git reset <file>Unstage file
git resetUnstage all
git reset --soft HEAD~1Undo commit (keep changes staged)
git reset --mixed HEAD~1Undo commit (keep changes unstaged)
git reset --hard HEAD~1Undo commit (delete changes)
git reset --hard HEADDiscard 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 --mergeReset with merge
git reset --patchInteractive 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..HEADRevert range
git revert --no-commit <commit>Revert without committing
git revert --continueContinue revert
git revert --abortAbort revert
git revert --editEdit revert message
git revert -nSame as –no-commit
git cleanRemove untracked files
git clean -nDry run
git clean -fForce remove
git clean -fdRemove directories too
git clean -fxRemove ignored files too
git clean -fXRemove only ignored
git clean -iInteractive 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

CommandDescription
git tagList tags
git tag -l "v1.*"List matching pattern
git tag -nList 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 --tagsPush all tags
git push origin --follow-tagsPush commits + tags
git push origin :refs/tags/<tag>Delete remote tag
git push --delete origin <tag>Delete remote tag
git fetch --tagsFetch tags
git pull --tagsPull 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

CommandDescription
git diffUnstaged changes
git diff --stagedStaged changes
git diff HEADAll 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 --cachedSame as –staged
git diff --name-onlyOnly file names
git diff --name-statusStatus + names
git diff --statStatistics
git diff --shortstatShort statistics
git diff --numstatNumeric statistics
git diff --summarySummary
git diff --checkCheck whitespace
git diff --color-wordsWord diff
git diff --word-diffWord diff alternative
git diff --patiencePatience algorithm
git diff --histogramHistogram algorithm
git diff --minimalMinimal diff
git diff --ignore-space-at-eolIgnore EOL whitespace
git diff --ignore-cr-at-eolIgnore CR at EOL
git diff --ignore-blank-linesIgnore blank lines
git diff --ignore-all-spaceIgnore all whitespace
git diff --ignore-space-changeIgnore whitespace changes
git diff --exit-codeExit 1 if differences
git diff --quietNo 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 --relativeRelative paths
git diff --patience -- <file>Combine options
git diff-tree <commit>Show tree diff
git diff-filesCompare with index
git diff-index <tree>Compare with tree

SECTION 14: CHERRY-PICK & REBASE

CommandDescription
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 --continueContinue after conflict
git cherry-pick --abortAbort cherry-pick
git cherry-pick --quitQuit but leave changes
git cherry-pick --no-commitApply without committing
git cherry-pick --editEdit commit message
git cherry-pick --signoffAdd Signed-off-by
git cherry-pick --keep-redundant-commitsKeep duplicates
git cherry-pick --strategy=recursive -X theirsUse theirs on conflict
git cherry-pick --strategy=recursive -X oursUse ours on conflict
git cherryFind commits not yet applied
git cherry -vVerbose
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 --3way3-way merge if needed
git am <patch>Apply mail patches
git am --continueContinue after conflict
git am --abortAbort
git am --skipSkip current patch
git am --resolvedMark resolved
git am -33-way merge
git am --signoffAdd signoff
git am --keep-crKeep carriage returns

SECTION 15: BISECT (BUG FINDING)

CommandDescription
git bisect startStart bisect session
git bisect start <bad> <good>Start with known bad/good
git bisect badMark current as bad
git bisect bad <commit>Mark commit as bad
git bisect good <commit>Mark commit as good
git bisect resetEnd bisect session
git bisect replay <log>Replay previous bisect
git bisect logShow bisect log
git bisect run <script>Auto bisect with script
git bisect skipSkip current commit
git bisect visualizeVisualize with gitk
git bisect termsShow terms
git bisect terms --term-bad=broken --term-good=workingCustom terms
git bisect nextMove to next commit (low-level)

SECTION 16: SUBMODULES

CommandDescription
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 initInitialize submodules
git submodule updateUpdate submodules
git submodule update --remoteUpdate to remote
git submodule update --initInit + update
git submodule update --recursiveUpdate nested
git submodule update --checkoutCheckout commit
git submodule update --rebaseRebase submodule
git submodule update --mergeMerge submodule
git submodule statusShow submodule status
git submodule foreach <command>Run command in each
git submodule foreach --recursive <command>Run recursively
git submodule syncSync URLs
git submodule sync --recursiveSync recursively
git submodule deinit <path>Unregister submodule
git submodule deinit --allUnregister all
git submodule set-url <path> <new-url>Change URL
git submodule absorbgitdirsMove gitdirs to superproject
git clone --recursive <url>Clone with submodules
git clone --recurse-submodules <url>Same as above
git pull --recurse-submodulesPull with submodules
git push --recurse-submodules=checkCheck submodules on push
git push --recurse-submodules=on-demandPush submodules too

SECTION 17: GITHUB SPECIFIC (gh CLI)

CommandDescription
gh auth loginLogin to GitHub
gh auth statusCheck auth status
gh auth logoutLogout
gh auth refreshRefresh token
gh repo create <name>Create repository
gh repo create <name> --publicPublic repo
gh repo create <name> --privatePrivate repo
gh repo create <name> --cloneClone after create
gh repo create <name> --pushPush after create
gh repo create <name> --template <template>From template
gh repo clone <repo>Clone repository
gh repo forkFork current repo
gh repo fork --cloneFork + clone
gh repo viewView repo info
gh repo view --webOpen in browser
gh repo listList your repos
gh repo list <user>List user’s repos
gh repo deleteDelete repository
gh repo archiveArchive repo
gh repo unarchiveUnarchive
gh repo rename <new-name>Rename repo
gh repo syncSync fork with upstream
gh repo set-defaultSet default repo
gh pr createCreate pull request
gh pr create --title "title" --body "body"With title+body
gh pr create --draftDraft PR
gh pr create --fillAuto fill from commits
gh pr create --base <branch>Set base branch
gh pr create --head <branch>Set head branch
gh pr create --assignee @meAssign 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 listList PRs
gh pr list --state openOpen PRs
gh pr list --state closedClosed PRs
gh pr list --state mergedMerged 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 10Limit results
gh pr viewView current PR
gh pr view <number>View specific PR
gh pr view --webOpen in browser
gh pr checkout <number>Checkout PR locally
gh pr diffShow PR diff
gh pr diff <number>Show specific PR diff
gh pr mergeMerge current PR
gh pr merge --mergeMerge commit
gh pr merge --squashSquash merge
gh pr merge --rebaseRebase merge
gh pr merge --delete-branchDelete branch after merge
gh pr merge --autoAuto merge when ready
gh pr reviewReview current PR
gh pr review --comment -b "message"Comment
gh pr review --approveApprove
gh pr review --request-changesRequest changes
gh pr comment <number> -b "message"Add comment
gh pr comment --editorUse editor
gh pr statusShow PR status
gh pr ready <number>Mark draft as ready
gh pr close <number>Close PR
gh pr reopen <number>Reopen PR
gh issue createCreate issue
gh issue create --title "title" --body "body"With title+body
gh issue create --assignee @meAssign 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 listList issues
gh issue list --state openOpen issues
gh issue list --state closedClosed 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 10Limit results
gh issue view <number>View issue
gh issue view --webOpen 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 listList gists
gh gist list --publicPublic gists
gh gist list --secretSecret gists
gh gist create <file>Create gist
gh gist create <file> --publicPublic gist
gh gist create <file> --desc "description"With description
gh gist view <id>View gist
gh gist view --webOpen in browser
gh gist clone <id>Clone gist
gh gist edit <id> <file>Edit gist
gh gist delete <id>Delete gist
gh alias listList aliases
gh alias set <name> <command>Create alias
gh alias delete <name>Delete alias
gh alias import -f <file>Import aliases
gh alias exportExport aliases
gh config set <key> <value>Set config
gh config get <key>Get config
gh config listList config
gh api <endpoint>Call GitHub API
gh api --method POST <endpoint> -f key=valuePOST request
gh api --paginatePaginate results
gh api --silentNo 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 listList extensions
gh extension install <repo>Install extension
gh extension upgrade <name>Upgrade extension
gh extension upgrade --allUpgrade all
gh extension remove <name>Remove extension
gh extension create <name>Create extension
gh release listList 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> --draftDraft release
gh release create <tag> --prereleasePre-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 listList workflows
gh workflow list --allAll workflows
gh workflow view <id>View workflow
gh workflow run <id>Run workflow
gh workflow run <id> -f key=valueWith inputs
gh workflow enable <id>Enable workflow
gh workflow disable <id>Disable workflow
gh run listList runs
gh run list --workflow <id>Filter by workflow
gh run view <id>View run
gh run view <id> --logView 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 listList codespaces
gh codespace createCreate 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 portsList forwarded ports
gh codespace ports visibility <port> publicMake port public
gh secret listList secrets
gh secret set <name>Set secret
gh secret set <name> -b <value>Set from clipboard
gh secret set <name> <fileSet from file
gh secret remove <name>Remove secret
gh secret list --org <org>Org secrets
gh variable listList variables
gh variable set <name>Set variable
gh variable set <name> -b <value>Set value
gh variable remove <name>Remove variable
gh label listList 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 listList milestones
gh milestone create <title>Create milestone
gh milestone create --due-date <date>With due date
gh milestone delete <number>Delete milestone
gh project listList 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 NameTrigger
pre-commitBefore commit
prepare-commit-msgBefore commit message editor
commit-msgAfter message is written
post-commitAfter commit completes
pre-rebaseBefore rebase
post-checkoutAfter checkout
post-mergeAfter merge
pre-pushBefore push
pre-receiveServer before receive
updateServer per branch
post-receiveServer after receive
post-updateServer after update
pre-auto-gcBefore garbage collection
post-rewriteAfter rewrite (rebase/amend)
applypatch-msgBefore applying patch
pre-applypatchBefore applying patch
post-applypatchAfter applying patch
sendemail-validateBefore sending email
fsmonitor-watchmanWatchman integration
p4-pre-submitPerforce before submit
post-index-changeAfter index changes

SECTION 19: .GITIGNORE PATTERNS

PatternMatches
*.logAll .log files
temp/Directory named temp
/temptemp in root only
tempAny file/dir named temp
!keep.logExcept keep.log
*.tmpAll .tmp files
*.swpVim swap files
.*.swpVim swap (hidden)
node_modules/Node modules
vendor/Go/PHP vendor
__pycache__/Python cache
*.pycPython compiled
.envEnvironment file
.env.*Environment files
.DS_StoreMac metadata
Thumbs.dbWindows thumbnails
dist/Build output
build/Build output
target/Rust/Java build
bin/Binaries
obj/Object files
*.exeWindows executables
*.dllDynamic libraries
*.soShared objects
*.dylibMac libraries
*.oObject files
coverage/Test coverage
.coverageCoverage file
*.logLogs
*.pidProcess IDs
*.seedSeed files
*.sockSockets
*.lockLock files
.vscode/VS Code settings
.idea/IntelliJ settings
*.imlIntelliJ module
.projectEclipse project
.classpathEclipse classpath
.settings/Eclipse settings
.vs/Visual Studio
*.suoVisual Studio
*.userVisual Studio
*.sln.docstatesVisual Studio
npm-debug.log*NPM logs
yarn-debug.log*Yarn logs
yarn-error.log*Yarn errors
package-lock.jsonNPM lock (sometimes)
yarn.lockYarn lock (sometimes)
pnpm-lock.yamlPNPM lock
.terraform/Terraform
*.tfstateTerraform state
*.tfstate.*Terraform state
*.tfvarsTerraform vars
.serverless/Serverless framework
.serverless_plugins/Serverless plugins
*.zipArchives
*.tarArchives
*.gzArchives
*.rarArchives
*.7zArchives
.env.localLocal env
.env.*.localLocal env files
*.keyPrivate keys
*.pemCertificates
*.crtCertificates
*.p12PKCS12
*.pfxPFX certificates
secrets/Secrets directory
credentials/Credentials
.secretsSecrets file
.vaultVault secrets

SECTION 20: GIT ALIASES (Common Setups)

AliasCommand
git cocheckout
git cobcheckout -b
git brbranch
git ststatus -sb
git cicommit -v
git ciacommit -a -v
git camcommit -am
git amendcommit --amend -C HEAD
git lglog --graph --oneline --decorate --all
git lgglog --graph --oneline --decorate
git histlog --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short
git unstagereset HEAD --
git lastlog -1 HEAD
git diffcdiff --cached
git dsdiff --staged
git dhdiff HEAD
git incominglog origin/main..HEAD --oneline
git outgoinglog HEAD..origin/main --oneline
git whoshortlog -sne
git ignoreupdate-index --assume-unchanged
git unignoreupdate-index --no-assume-unchanged
git trackedls-tree --full-tree -r HEAD
git untrackedls-files --others --exclude-standard
git tagstag -ln
git graphlog --graph --oneline --all --decorate --simplify-by-decoration
git treelog --graph --pretty=oneline --abbrev-commit --all
git fixupcommit --fixup
git squashcommit --squash
git rootrev-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 undoreset --soft HEAD^
git redoreset --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 CodeMeaning
1General error
128Invalid arguments/usage
129Usage error
130Merge conflict
137Out of memory
139Segmentation fault
255Git internal error

SECTION 22: ENVIRONMENT VARIABLES

VariablePurpose
GIT_AUTHOR_NAMEOverride author name
GIT_AUTHOR_EMAILOverride author email
GIT_AUTHOR_DATEOverride author date
GIT_COMMITTER_NAMEOverride committer name
GIT_COMMITTER_EMAILOverride committer email
GIT_COMMITTER_DATEOverride committer date
GIT_EDITORSet editor
GIT_PAGERSet pager
GIT_SSHSSH command
GIT_SSH_COMMANDSSH command with options
GIT_ASKPASSAskpass program
GIT_DIR.git directory path
GIT_WORK_TREEWork tree path
GIT_INDEX_FILEIndex file path
GIT_OBJECT_DIRECTORYObjects directory
GIT_ALTERNATE_OBJECT_DIRECTORIESAlternate object locations
GIT_HTTP_PROXYHTTP proxy
GIT_HTTPS_PROXYHTTPS proxy
GIT_NO_PROXYNo proxy domains
GIT_CONFIG_GLOBALGlobal config path
GIT_CONFIG_SYSTEMSystem config path
GIT_FLUSHFlush output
GIT_TRACETrace output
GIT_TRACE_PACKETPacket trace
GIT_TRACE_PERFORMANCEPerformance trace
GIT_TRACE_SETUPSetup trace
GIT_MERGE_VERBOSITYMerge verbosity
GIT_CEILING_DIRECTORIESCeiling directories
GIT_DISCOVERY_ACROSS_FILESYSTEMCross FS discovery
GIT_OPTIONAL_LOCKSOptional locks
GIT_PAGER_IN_USEPager active
GIT_SEQUENCE_EDITORRebase todo editor
GIT_SKIP_TESTSSkip tests
GIT_TERMINAL_PROMPTTerminal prompts
GIT_CLONE_PROTECTION_ACTIVEClone protection
GIT_PROTOCOLProtocol version
GIT_NAMESPACENamespace
GIT_REFLOG_ACTIONReflog action
GIT_REF_PARANOIAParanoid ref checks

SECTION 23: COMMIT MESSAGE CONVENTIONS (Conventional Commits)

TypeDescription
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)

VersionMeaning
v1.0.0Major.Minor.Patch
MajorBreaking changes
MinorNew features (backward compatible)
PatchBug fixes
v1.0.0-alphaAlpha pre-release
v1.0.0-betaBeta pre-release
v1.0.0-rc.1Release candidate

SECTION 25: GIT REFERENCE SHORTCUTS

ShortcutMeaning
HEADCurrent commit
HEAD^Parent of HEAD
HEAD^^Grandparent
HEAD~11 commit back
HEAD~55 commits back
HEAD^2Second parent (merge)
HEAD~3^23 back, then second parent
HEAD@{0}Current position
HEAD@{1}Previous position
HEAD@{5.minutes.ago}Position 5 minutes ago
main~33 commits before main
main..featureCommits in feature not in main
main...featureCommits 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
Leave A Reply

Your email address will not be published.