Git Commands Cheat Sheet

Search and filter common Git commands for setup, commits, branches, remotes, recovery, debugging, and advanced workflows.

0 of 45 commands
Command Category Purpose Example Notes
git init Setup Create a new Git repository in the current folder. git init Creates a .git directory.
git clone Setup Copy an existing remote repository locally. git clone https://github.com/user/repo.git Creates a new local folder by default.
git status Inspect Show working tree status, staged files, branch info, and changes. git status One of the most commonly used Git commands.
git add Stage Stage file changes for the next commit. git add file.js Use git add . to stage all changes in the current directory.
git restore --staged Stage Unstage a file without changing the working copy. git restore --staged file.js Modern replacement for many reset unstaging workflows.
git commit Commit Create a commit from staged changes. git commit -m "Update homepage" Commits are local until pushed.
git commit --amend Commit Modify the most recent commit. git commit --amend Avoid amending commits already shared unless you understand force push impact.
git log Inspect Show commit history. git log --oneline --graph --decorate Useful for reviewing recent commits and branch structure.
git diff Inspect Show unstaged changes. git diff Compares working tree changes against the index.
git diff --staged Inspect Show staged changes. git diff --staged Shows what will be included in the next commit.
git branch Branch List, create, or delete branches. git branch Use git branch new-branch to create a branch.
git switch Branch Switch branches. git switch main Modern branch-switching command.
git switch -c Branch Create and switch to a new branch. git switch -c feature/login Equivalent to creating a branch then switching to it.
git checkout Branch Older multi-purpose command for switching branches or restoring files. git checkout main Still common, but git switch and git restore are clearer for many workflows.
git merge Branch Merge another branch into the current branch. git merge feature/login Creates a merge commit unless fast-forward is possible.
git rebase Branch Replay commits on top of another base commit. git rebase main Useful for linear history. Avoid rebasing shared branches without caution.
git cherry-pick Commit Apply a specific commit onto the current branch. git cherry-pick abc1234 Useful for selectively moving a commit.
git stash Working Tree Temporarily save uncommitted changes. git stash Useful before switching branches or pulling changes.
git stash pop Working Tree Reapply and remove the latest stash. git stash pop May cause conflicts if files changed.
git stash list Working Tree List saved stashes. git stash list Shows stash entries like stash@{0}.
git restore Working Tree Restore files in the working tree. git restore file.js Discards unstaged changes for the file.
git reset Undo Move HEAD and optionally reset index and working tree. git reset --soft HEAD~1 Powerful undo command. Be careful with --hard.
git reset --hard Undo Reset index and working tree to a commit, discarding local changes. git reset --hard HEAD Destructive for uncommitted work.
git revert Undo Create a new commit that undoes an earlier commit. git revert abc1234 Safer than reset for shared history.
git clean Undo Remove untracked files from the working tree. git clean -fd Destructive. Use git clean -n first to preview.
git remote Remote Manage remote repository connections. git remote -v Common remote name is origin.
git remote add Remote Add a remote repository. git remote add origin https://github.com/user/repo.git Used when connecting a local repo to GitHub or another host.
git fetch Remote Download remote refs and objects without merging. git fetch origin Safe way to update remote-tracking info.
git pull Remote Fetch and integrate remote changes into the current branch. git pull origin main Usually fetch plus merge, unless configured for rebase.
git push Remote Upload local commits to a remote branch. git push origin main Use -u to set upstream on first push.
git push -u Remote Push and set upstream tracking for the branch. git push -u origin feature/login After this, git push and git pull can infer the remote branch.
git push --force-with-lease Remote Force push more safely by checking remote state first. git push --force-with-lease Safer than --force, but still rewrites remote history.
git tag Tag List, create, or delete tags. git tag v1.0.0 Tags are often used for releases.
git tag -a Tag Create an annotated tag. git tag -a v1.0.0 -m "Release v1.0.0" Annotated tags include metadata and a message.
git show Inspect Show details for commits, tags, or objects. git show abc1234 Useful for inspecting a specific commit.
git blame Inspect Show line-by-line commit attribution for a file. git blame file.js Useful for tracking when and why a line changed.
git grep Search Search tracked files for text or patterns. git grep "function render" Fast repository-aware search.
git shortlog Inspect Summarize commits by author. git shortlog -sn Useful for contributor summaries.
git config Config Read or write Git configuration. git config --global user.name "Your Name" Can be local, global, or system-level.
git config --global user.email Config Set the email used for commits. git config --global user.email "you@example.com" Important for GitHub commit attribution.
git reflog Recovery Show recent movements of HEAD and branch refs. git reflog Useful for recovering commits after reset, rebase, or checkout mistakes.
git bisect Debug Find the commit that introduced a bug using binary search. git bisect start Powerful for regression debugging.
git worktree Advanced Manage multiple working trees from one repository. git worktree add ../repo-feature feature/login Useful for working on multiple branches at once.
git submodule Advanced Manage nested repositories inside a repository. git submodule update --init --recursive Common in projects that vendor external repositories.
git archive Export Create an archive of files from a commit or branch. git archive --format=zip HEAD > source.zip Exports tracked files without the .git directory.

About this tool

Git Reference helps developers, QA engineers, technical writers, and support teams search and filter common Git commands with examples and notes. Use it during debugging sessions, documentation updates, code reviews, and integration tests when you need a focused result you can read, copy, or share without opening a heavier application.

Use cases

  • Use Git Reference during debugging when you need to search and filter common Git commands with examples and notes without leaving the browser.
  • Copy Git Reference output into tickets, docs, test notes, spreadsheets, or chat threads so teammates can verify the same result.
  • Keep Git Reference open as a repeatable browser utility for quick checks instead of building a one-off spreadsheet or script.

FAQ

What is Git Reference best used for?

Git Reference is best used when you need to search and filter common Git commands with examples and notes in a fast, copy-friendly browser workflow.

Who benefits most from the Git Reference tool?

It is especially helpful for developers, QA engineers, technical writers, and support teams who handle debugging sessions, documentation updates, code reviews, and integration tests, and need clear output without extra setup.

Can I use Git Reference results in documentation or bug reports?

Yes. The output is designed to be readable and easy to paste into issues, docs, QA notes, or team conversations.