Git Cheat Sheet

Essential Git commands β€” setup, branching, merging, rebasing, stashing, and more. Click any command to copy.

Copied!

What is Git Cheat Sheet?

Git Cheat Sheet is a quick reference for the most commonly used Git commands, organized by workflow stage: setting up a repository, staging and committing changes, branching, merging, rebasing, working with remotes, undoing changes, and inspecting history. Each command includes a concise explanation and example.

Git is the distributed version control system used by virtually every software project. It tracks changes to files over time, enables multiple developers to work simultaneously without overwriting each other, and provides a complete history of every change ever made. GitHub, GitLab, and Bitbucket are hosting platforms built on top of Git.

The most common commands developers look up: git stash (save work-in-progress), git rebase -i HEAD~N (interactive rebase to clean up commits), git log --oneline --graph (visual branch history), git bisect (binary search for the commit that introduced a bug), and git cherry-pick (apply a specific commit to the current branch).

How to Use

  1. Find the operation you need in the category list (Setup, Stage, Branch, Remote, Undo, etc.).
  2. Click any command to copy it to your clipboard.
  3. Use the search box to filter commands by keyword.
  4. Use the Examples toggle to show or hide example output for each command.
  5. Bookmark this page for quick access during development.

Examples

Start a new repo

Result: git init β€” creates a .git directory in the current folder / git clone β€” copies a remote repo locally

Save uncommitted work temporarily

Result: git stash β€” saves changes and clears working directory / git stash pop β€” restores the last stash

Interactive rebase to squash 3 commits

Result: git rebase -i HEAD~3 β€” opens editor to combine, reorder, or edit the last 3 commits before pushing

Frequently Asked Questions

What is the difference between git merge and git rebase?

git merge creates a merge commit that joins two branch histories, preserving both timelines. git rebase rewrites your branch commits on top of the target, creating a linear history. Rebase makes history cleaner but rewrites commit hashes β€” never rebase commits that have been pushed to a shared branch.

What is git stash and when should I use it?

git stash temporarily saves your uncommitted changes and reverts the working directory to a clean state. Use it to quickly switch branches without committing half-done work. git stash pop restores the saved changes.

How do I undo a commit that has already been pushed?

Use git revert β€” this creates a new commit that undoes the changes, preserving history. Never use git reset --hard on pushed commits β€” it rewrites history and breaks other contributors. git revert is the safe, collaborative approach.

What is the difference between git fetch and git pull?

git fetch downloads changes from the remote but does not update your working files β€” you decide when to merge. git pull is git fetch plus git merge in one command. Prefer fetch plus explicit merge when you want to inspect changes before integrating them.

How do I resolve a merge conflict?

Git marks conflict regions in files with markers. Open each conflicted file, choose or combine the changes, remove the markers, then git add the file and git commit to complete the merge. Use a merge tool or your editor for a better visual experience.

Related Tools