Git & GitHub Cheatsheet

Complete Git & GitHub CLI command reference — searchable, fast, always free

🔍

Click or hover any command for a longer description & example

Setup & Config
git config --global user.nameSet global username
git config --global user.emailSet global email
git config --listShow all config values
git initInitialize new repository
git clone <url>Clone a remote repository
Daily Workflow
git statusShow working tree status
git add <file>Stage a specific file
git add .Stage all changes in current directory
git add -pInteractively stage chunks
git commit -m "msg"Commit with message
git commit -am "msg"Commit all tracked changes
git commit --amendAmend the last commit
git pushPush current branch to its upstream
git pullFetch and integrate changes (merge or rebase)
git fetchFetch without merging
Branching
git branchList all branches
git branch <name>Create new branch
git switch <branch>Switch to branch
git checkout -b <name>Create & switch to new branch
git merge <branch>Merge branch into current
git rebase <branch>Rebase onto branch
git cherry-pick <commit>Apply a specific commit
git branch -d <name>Delete local branch
git push origin --delete <name>Delete remote branch
Diffs & Logs
git diffShow unstaged changes
git diff --stagedShow staged changes
git log --onelineCompact commit history
git log --oneline --graph --decorate --allVisual branch graph (all branches)
git show <commit>Show commit details & diff
git blame <file>Show who changed each line
git reflogShow full HEAD history
Undoing Things
git restore <file>Discard working dir changes
git reset HEAD <file>Unstage a file
git reset --soft HEAD~1Undo commit, keep staged
git reset --hard HEAD~1Undo commit & discard changes
git revert <commit>Create a revert commit
Stashing
git stashStash current changes
git stash listList all stashes
git stash popApply & remove latest stash
git stash dropDiscard a stash (latest by default)
git stash apply stash@{n}Apply a specific stash
Remotes & Tags
git remote -vList remotes with URLs
git remote add origin <url>Add remote origin
git push -u origin <branch>Push & set upstream
git tagList all tags
git tag v1.0Create lightweight tag
git push origin --tagsPush all tags to remote
Repos & Auth gh cli
gh auth loginAuthenticate with GitHub
gh auth statusShow authentication status
gh repo createCreate a new repository
gh repo clone <user/repo>Clone a repository
gh repo viewView repo info in terminal
Pull Requests gh cli
gh pr createOpen a new pull request
gh pr listList open pull requests
gh pr viewView current branch PR
gh pr mergeMerge a pull request
gh pr checkout <number>Check out a PR locally
gh pr review --approveApprove a pull request
Issues gh cli
gh issue createCreate a new issue
gh issue listList open issues
gh issue view <number>View issue details
gh issue close <number>Close an issue
Actions & Releases gh cli
gh run listList recent workflow runs
gh run view <id>View a workflow run
gh run watchWatch a run in real-time
gh release createCreate a new release
gh release listList all releases