This Git cheat sheet lists the most-used Git commands for everyday version control — setting up a repo, staging and committing, branching, working with remotes, inspecting history and undoing changes.
Setup & create
| 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 |
| git clone <url> | Copy a remote repository |
Stage & commit
| Command | What it does |
|---|
| git status | Show changed files |
| git add <file> | Stage a file |
| git add . | Stage everything |
| git commit -m "message" | Commit staged changes |
| git commit -am "message" | Stage tracked files and commit |
Branches
| Command | What it does |
|---|
| git branch | List branches |
| git switch -c <name> | Create and switch to a branch |
| git switch <name> | Switch branch |
| git merge <name> | Merge a branch into current |
| git branch -d <name> | Delete a branch |
Remotes
| Command | What it does |
|---|
| git remote add origin <url> | Link a remote |
| git push -u origin main | Push and set upstream |
| git push | Upload commits |
| git pull | Fetch and merge from remote |
| git fetch | Download without merging |
Inspect & undo
| Command | What it does |
|---|
| git log --oneline | Compact history |
| git diff | Show unstaged changes |
| git restore <file> | Discard file changes |
| git reset --hard | Reset to last commit |
| git revert <commit> | Undo a commit safely |
| git stash | Shelve changes |
| git stash pop | Restore shelved changes |
Related tools & charts