Back to Reference Guides
Developer ReferenceGit 2.40+ Compatible
Git & GitHub CLI Commands Cheat Sheet
Everyday Git commands for repository setup, staging, branching, rebasing, stashing, and conflict resolution.
Repository Setup & Initialization
git initInitialize an existing directory as a new Git repositorygit clone <repo-url>Clone an existing remote repository onto your local machinegit statusCheck modified, staged, and untracked files in the working directorygit log --oneline --graph --decorateView commit history as a clean, single-line visual branch treeStaging & Committing Changes
git add <file>Stage a single file for the next commitgit add .Stage all modified and new files in the current working directorygit commit -m "feat: descriptive message"Commit staged snapshot with an atomic messagegit commit --amend --no-editAdd staged changes to the most recent commit without editing messagegit diffShow unstaged changes between working directory and the staging areagit diff --stagedShow changes between staged files and the last commitBranching & Switching Contexts
git branchList all local branches (* marks the active branch)git branch -aList both local and remote-tracking branchesgit switch -c <branch-name>Create a new branch and switch to it immediatelygit switch <branch-name>Switch to an existing local branchgit branch -d <branch-name>Safely delete a merged local branchgit branch -D <branch-name>Force delete a branch regardless of merge statusMerging, Rebasing & Remote Sync
git pull origin <branch>Fetch from remote repository and merge into current active branchgit push origin <branch>Push local branch commits to the remote tracking repositorygit merge <branch>Merge specified branch into current active branchgit rebase <base-branch>Re-apply current branch commits on top of another branch tipgit remote -vDisplay all configured remote repository names and URLsStashing, Undoing & Resetting
git stashTemporarily shelve uncommitted working directory changesgit stash popRe-apply the most recently shelved changes and remove from stash listgit stash listInspect all shelved stashesgit restore <file>Discard uncommitted changes in working directory to match HEADgit restore --staged <file>Unstage a file while preserving its working directory modificationsgit revert <commit-hash>Create a new commit that safely inverts changes of a previous commitgit reset --soft HEAD~1Undo last commit but keep changes staged in indexgit reset --hard HEAD~1⚠️ Dangerously destroy last commit and discard all uncommitted changes