Git is the version control system behind nearly every software project. These are the commands you reach for day to day, grouped by task, each with a one-line description.
Setup & clone
| Command | What it does |
|---|---|
git config --global user.name "Name" |
Set your commit name |
git config --global user.email "[email protected]" |
Set your commit email |
git init |
Start a new repository in this folder |
git clone <url> |
Copy a remote repository locally |
Stage & commit
| Command | What it does |
|---|---|
git status |
Show changed and staged files |
git add <file> |
Stage a file (use . for all) |
git commit -m "msg" |
Commit staged changes with a message |
git commit -am "msg" |
Stage tracked files and commit in one step |
git diff |
Show unstaged changes |
Branches
| Command | What it does |
|---|---|
git branch |
List branches |
git branch <name> |
Create a branch |
git checkout <name> |
Switch to a branch |
git switch -c <name> |
Create and switch in one step |
git merge <name> |
Merge a branch into the current one |
git branch -d <name> |
Delete a branch |
Remote
| Command | What it does |
|---|---|
git remote -v |
List remotes |
git remote add origin <url> |
Add a remote named origin |
git push -u origin main |
Push and set the upstream |
git push |
Push commits to the remote |
git pull |
Fetch and merge from the remote |
git fetch |
Download changes without merging |
Undo & history
| Command | What it does |
|---|---|
git log --oneline |
Compact commit history |
git restore <file> |
Discard changes to a file |
git reset <file> |
Unstage a file |
git reset --hard <commit> |
Reset everything to a commit (destructive) |
git revert <commit> |
Make a new commit that undoes one |
git stash |
Shelve changes for later; git stash pop to restore |
Frequently Asked Questions
What is Git?
Git is a distributed version control system that tracks changes to files so teams can work on the same code without overwriting each other.
What is the difference between git pull and git fetch?
Fetch downloads changes from the remote without touching your files. Pull does a fetch and then merges those changes into your branch.
How do I undo the last commit but keep my changes?
Use git reset with the soft option pointing at the previous commit, which keeps your edits staged.
What does git stash do?
It shelves your uncommitted changes so your working folder is clean, then lets you reapply them later with stash pop.
Browse our free developer tools for more.