Start a repository
git initgit add .git commit -m "Initial commit"
Find the command you need without breaking your flow. Search this practical Git cheat sheet online, copy a command, and get back to shipping.
Three safe, everyday sequences for when you need more than one command.
git initgit add .git commit -m "Initial commit"git switch -c feature/namegit add -pgit commit -m "Describe change"git push -u origin HEADgit fetch origingit rebase origin/maingit push --force-with-leaseSearch by command or task, such as undo commit, new branch or see changes.
The commands you will reach for most often.
git statusShow changed, staged and untracked files.
git add <file>Stage one file for the next commit.
git add .Stage all changes in the current directory.
git add -pInteractively choose which change hunks to stage.
git commit -m "message"Commit staged changes with a short message.
git pullFetch and integrate the current remote branch.
git pushUpload local commits to the tracked remote.
git diffView changes that have not been staged yet.
Configure Git and create or copy a repository.
git config --global user.name "Name"Set the author name used for your commits.
git config --global user.email "you@example.com"Set the email attached to your commits.
git config --listList the Git settings currently in effect.
git initCreate a Git repository in the current folder.
git clone <url>Download a repository into a new local folder.
git clone -b <branch> <url>Clone a repository and check out one branch.
Understand exactly what changed before you commit.
git diff --stagedView changes already staged for the next commit.
git diff -- <file>Show unstaged changes for one file only.
git show <commit>Display a commit and the patch it introduced.
git log --onelineRead a compact list of recent commits.
git log --graph --oneline --allSee branch and merge history as a compact graph.
git blame <file>Show who last changed each line in a file.
git clean -nPreview which untracked files Git would remove.
Create, switch, combine and tidy up branches.
git branchList local branches and highlight the current one.
git switch <branch>Move to an existing local branch.
git switch -c <branch>Create a new branch and switch to it.
git branch -m <new-name>Rename the branch you are currently on.
git merge <branch>Merge another branch into the current branch.
git merge --abortStop a conflicted merge and restore the pre-merge state.
git branch -d <branch>Delete a local branch after it has been merged.
git rebase mainReplay your branch commits on top of local main.
Connect local work with a shared repository.
git remote -vList remote names and their fetch and push URLs.
git remote add origin <url>Connect the repository to a remote named origin.
git fetch originDownload origin's latest branches and commits.
git pull --rebaseUpdate your branch and replay local commits on top.
git push -u origin HEADPush the current branch and set its upstream.
git push --tagsUpload all local tags to the remote.
git push --force-with-leaseSafely update a remote after rebasing local commits.
git push origin --delete <branch>Delete a branch from the origin remote.
Back out changes with the least surprising option.
git revert. Reset rewrites local history and can disrupt collaborators if the commits were already pushed.git restore <file>Discard unstaged changes in one file.
git restore --staged <file>Unstage a file while keeping its changes.
git commit --amendReplace the last commit with your staged changes.
git reset --soft HEAD~1Undo the last commit but keep changes staged.
git reset HEAD~1Undo the last commit and keep changes unstaged.
git revert <commit>Create a new commit that reverses an old one.
git reflogFind recent HEAD positions and recover lost commits.
Pause unfinished changes and restore them later.
git stashTemporarily store tracked, uncommitted changes.
git stash push -m "message"Stash changes with a description you will recognize.
git stash -uStash tracked changes and untracked files.
git stash listList saved stashes from newest to oldest.
git stash popApply the latest stash and remove it from the list.
git stash apply stash@{0}Apply a specific stash without deleting it.
Search commits, reuse changes and mark versions.
git log --author="name"Find commits by a particular author.
git log --grep="text"Search commit messages for matching text.
git log --follow -- <file>Trace a file's history across renames.
git cherry-pick <commit>Apply one existing commit to the current branch.
git tagList the tags stored in the repository.
git tag -a v1.0.0 -m "Release v1.0.0"Create an annotated tag for a release.
git bisect startBegin a binary search for the commit that caused a bug.
Try a simpler task such as “branch”, “undo”, “remote” or “history”.
Text inside angle brackets is a placeholder, not part of the command. Replace it with your real value and omit the brackets.
git switch -c <branch>git switch -c checkout-fixThis online Git command cheat sheet is organized by the task you are trying to finish, not by obscure flags. Search for an outcome, read the plain-language description and copy the exact command you need.
Run git status before a commit, merge, rebase or reset. It gives you the quickest picture of your current state.
Use git add -p to stage related hunks. Focused commits are easier to review, revert and understand later.
Prefer git revert for changes already pushed to a shared branch. Use reset mainly for local, unpublished work.
The most common Git commands are git status, git add, git commit, git pull, git push, git switch, git diff and git log. Together they cover checking your work, staging and saving changes, syncing, changing branches and reading history.
Select the Copy button beside any command. You can also search or choose a category, then select Copy visible to copy the current results as a grouped reference. Replace any placeholder inside angle brackets before running the command.
If the commit is local, git reset --soft HEAD~1 removes it while keeping the changes staged. If the commit was pushed or shared, git revert HEAD is usually safer because it preserves history and adds a new commit that reverses the change.
Yes. It is free to use online with no account, installation or sign-up. Search and copy interactions happen directly in your browser.
Yes. The commands on this page are standard Git commands. They work with local repositories and with remotes hosted by GitHub, GitLab, Bitbucket or another Git hosting provider.
Test patterns, clean up data and generate useful identifiers.