Git Cheat Sheet
Search git commands. Copy. Done.
Search git commands. Copy. Done.
77 commands found
git initInitialize a new git repository in the current directory
git clone <url>Clone a remote repository to your local machine
git config --global user.name <name>Set your global git username for commits
git config --global user.email <email>Set your global git email for commits
git config --listView all current git configuration settings
git statusShow the current status of the working directory and staging area
git add <file>Stage specific file(s) for commit
git add .Stage all modified and new files in the current directory
git add -AStage all changes (modified, new, and deleted files) in the entire repo
git rm <file>Remove file from working directory and staging area
git restore <file>Discard changes to file(s) in working directory
git commit -m <message>Create a new commit with a descriptive message
git commit -a -m <message>Stage all tracked changes and commit in one command
git commit --amendModify the most recent commit (message or changes)
git logView commit history with full details (exit with 'q')
git log --onelineShow compact commit history with short hashes
git log --graph --oneline --allVisualize branch structure and commit history
git show <commit>Display the changes in a specific commit
git show HEADShow the changes in the most recent commit
git branchList all local branches (current branch marked with *)
git branch -aList all branches (local and remote)
git branch <branch-name>Create a new branch from current HEAD
git branch -d <branch-name>Delete a branch (safe - prevents loss of unmerged work)
git branch -D <branch-name>Force delete a branch (use with caution)
git branch -m <old-name> <new-name>Rename a branch
git checkout <branch-name>Switch to an existing branch
git checkout -b <branch-name>Create a new branch and switch to it in one command
git switch <branch-name>Switch to a branch (modern alternative to checkout)
git switch -c <branch-name>Create and switch to a new branch (modern)
git merge <branch-name>Merge another branch into the current branch
git merge --no-ff <branch-name>Merge with a merge commit (preserves branch history)
git rebase <branch-name>Reapply current branch commits on top of another branch
git rebase -i HEAD~<n>Interactive rebase last n commits (edit, squash, reorder)
git merge --abortCancel a merge in progress
git rebase --abortCancel a rebase in progress
git remoteList all remote repositories
git remote -vList remote repositories with their URLs
git remote add <name> <url>Add a new remote repository connection
git remote remove <name>Remove a remote repository connection
git remote set-url <name> <new-url>Change the URL of an existing remote repository
git remote remove origin && git remote add origin <url>Remove origin remote and add a new one (useful after cloning)
git push <remote> <branch>Push commits to a remote branch
git push -u <remote> <branch>Push branch and set upstream tracking (use first time)
git push --allPush all branches to remote
git push --force-with-leaseForce push safely (respects remote changes)
git push --delete <remote> <branch>Delete a branch on remote repository
git pullFetch and merge remote changes into current branch
git pull <remote> <branch>Fetch and merge specific remote branch
git fetchDownload remote changes without merging
git fetch <remote>Fetch from a specific remote
git reset --soft HEAD~1Undo last commit, keep changes staged
git reset --mixed HEAD~1Undo last commit, keep changes in working directory
git reset --hard HEAD~1Undo last commit and discard all changes (irreversible)
git revert <commit>Create new commit that undoes specific commit (safe)
git stashSave uncommitted changes temporarily
git stash save <message>Stash with a descriptive message
git stash listShow all stashed changes
git stash popApply most recent stash and remove it
git stash applyApply stash without removing it
git stash dropDelete most recent stash
git clean -fdRemove untracked files and directories
git restore --staged <file>Unstage file(s)
git diffShow all unstaged changes (exit with 'q')
git diff --stagedShow staged changes ready to commit
git diff <branch1> <branch2>Compare two branches
git diff <commit1> <commit2>Compare two commits
git tag <tag-name>Create a lightweight tag (e.g., for releases)
git tag -a <tag-name> -m <message>Create an annotated tag with message
git tag -lList all tags
git push --tagsPush all tags to remote
git push origin <tag-name>Push specific tag to remote
git blame <file>Show who changed each line (author and commit)
git bisect startBegin binary search for commit that introduced bug
git log --grep <pattern>Search commit messages for pattern
git log -S <string>Find commits that added/removed specific code
git log --author <name>Show commits by specific author
git reflogShow history of HEAD changes (recover lost commits)
--help flag on any command for detailed documentation| for powerful workflowsgit status often to understand your repository state