git clone git@example.com:me/project.gitCopy a repository, with its whole history, into a new folder.
Cheat sheet
The everyday Git workflow, plus how to get out of trouble when a commit, a branch or a rebase goes sideways.
Nothing you type here is sent or saved. Privacy policy
Fill in a branch name or a message once and every command below uses it. Messages and names with spaces are quoted for you.
Nothing matches that. Try fewer words, or a shorter one.
git clone git@example.com:me/project.gitCopy a repository, with its whole history, into a new folder.
git initStart a new repository in the current folder.
git config --global user.name 'Jo Bloggs'Set the name that goes on your commits.
git config --global user.email jo@example.comSet the email that goes on your commits.
git status -sbWhat's changed, in a short list, with the branch at the top.
-s-bgit diffThe changes you haven't staged yet.
git diff --stagedExactly what the next commit will contain.
git add README.mdStage a file for the next commit.
git add -pGo through your changes piece by piece and pick what to stage. y yes, n no, s split it smaller.
git commit -m 'Fix the login redirect'Commit what's staged.
git commit --amend --no-editAdd what's staged to your last commit. Only before you've pushed it.
git pull --rebaseGet the latest, and put your own commits on top of it instead of making a merge commit.
git push -u origin feature/loginThe first push of a new branch. After this, plain git push is enough.
-ugit switch -c feature/loginMake a new branch and move to it.
-cgit switch feature/loginMove to a branch that already exists.
git branch -aEvery branch, including the ones on the remote.
git merge feature/loginBring another branch's work into the one you're on.
git rebase feature/loginReplay your branch's commits on top of another branch, for a straight-line history.
git branch -d feature/loginDelete a branch you've finished with. Git refuses if it isn't merged yet (-D insists).
git push origin --delete feature/loginDelete the branch on the remote too.
git fetch --pruneCatch up with the remote, and forget branches that were deleted there.
git log --oneline --graph -20The last 20 commits, one line each, with branches drawn in.
git log -p -- README.mdEvery change ever made to one file.
-p--git show a1b2c3dOne commit: who, when, why and what.
git blame README.mdWho last changed each line, and in which commit.
git log -S TODO --onelineThe commits that added or removed some text. Finds when something appeared or vanished.
git grep -n TODOSearch every tracked file. Faster than grep, and it skips what Git ignores.
git restore README.mdThrow away your unsaved-to-Git changes to a file. They're gone for good.
git restore --staged README.mdUnstage a file, keeping the changes.
git restore --source=a1b2c3d README.mdPut a file back the way it was in an older commit.
git reset --soft HEAD~1Undo the last commit, but keep its changes staged, ready to commit again.
git revert a1b2c3dMake a new commit that undoes an old one. The safe way to undo something already pushed.
git reset --hard origin/feature/loginMake your branch match the remote exactly. Throws away your local commits and changes, so be sure.
git reflogEverywhere your branch has pointed lately. How to find a commit "lost" to a bad reset or rebase.
git clean -nShow the untracked files that git clean -f would delete. Look before you leap.
git clean -fdDelete untracked files and folders.
-f-dgit stash push -u -m 'Fix the login redirect'Park your changes for later, so you can switch branches with a clean slate.
-u-mgit stash listEverything you've parked.
git stash popBring the latest stash back, and drop it from the list.
git rebase -i HEAD~3Tidy up your last few commits before you push: reorder, squash, reword or drop them.
pickrewordsquashdropgit rebase --continueCarry on after fixing a conflict (git add the fixed files first).
git rebase --abortGive up and go back to exactly where you were before the rebase.
git cherry-pick a1b2c3dCopy one commit from another branch onto this one.
git tag -a v1.2.0 -m 'Fix the login redirect'Mark a release.
-agit push origin v1.2.0Push a tag. Plain git push leaves tags behind.
git remote -vWhere this repository fetches from and pushes to.
git remote add origin git@example.com:me/project.gitAdd another remote.
git remote set-url origin git@example.com:me/project.gitPoint a remote at a new address, after a move.