Git Commands Cheat Sheet

This page is a quick reference for the Git commands we learned in this tutorial. Keep it open while you practice. Most commands link to their full chapter.

Setup and start

CommandDescription
git config --global user.name "Name"Set your name
git config --global user.email "mail"Set your email
git initCreate a new repository (details)
git clone <url>Copy a remote repository (details)

Save changes

CommandDescription
git statusSee changed and staged files (details)
git add <file>Stage a file (details)
git add .Stage all changes in the folder
git commit -m "msg"Save the staged changes (details)
git commit --amendChange the last commit (details)
git rm <file> / git mv a bDelete or rename a file (details)

See history and differences

CommandDescription
git log --onelineShort list of commits (details)
git diffChanges not staged (details)
git diff --stagedChanges staged for the next commit
git show <commit>Show one commit
git reflogHistory of where HEAD moved (details)

Branches

CommandDescription
git branchList branches (details)
git switch -c <name>Create and move to a branch (details)
git switch <name>Move to a branch
git merge <name>Merge a branch into the current one (details)
git rebase <name>Replay commits on top of another branch (details)
git cherry-pick <commit>Copy one commit (details)
git branch -d <name>Delete a merged branch

Remote repositories

CommandDescription
git remote -vList remotes (details)
git pushUpload commits (details)
git fetchDownload commits without merging (details)
git pullFetch and merge
git push origin --delete <branch>Delete a remote branch

Undo things

CommandDescription
git restore <file>Discard changes of a file (details)
git restore --staged <file>Unstage a file
git reset --soft HEAD~1Undo the commit, keep changes staged (details)
git reset --hard HEAD~1Undo the commit and delete the changes
git revert <commit>Undo a commit with a new commit (details)
git clean -fdDelete untracked files and folders

Extra tools

CommandDescription
git stash / git stash popPut work aside and bring it back (details)
git tag -a v1.0 -m "msg"Mark a release (details)
git submodule add <url>Add a repository inside a repository (details)
Note: Learned all of it? Now test yourself with the Git interview questions and exercises on this website.

Congratulations! Chapter Finished. Learn more about the similar topics:
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.