Use this Git command cheat sheet for everyday repository tasks. Commands shown with placeholders such as [file] or [branch] need values from your project. Run Git from the repository directory unless noted.
Start a repository
git init
git clone [url]
git init creates a repository in the current directory. git clone copies an existing remote repository to your computer.
Stage and commit changes
git status
git add [file]
git add .
git commit -m "Describe the change"
Use git status to review changed and staged files. Stage specific files with git add [file]; git add . stages changes under the current directory, so review the status before committing.
Inspect history and branches
git log --oneline
git branch
git switch [branch]
git switch -c [new-branch]
git branch lists local branches. git switch changes branches, while git switch -c creates and checks out a new branch. Merge another branch into the current branch with git merge [branch].
Work with a remote
git remote -v
git remote add origin [url]
git fetch origin
git pull
git push -u origin [branch]
git fetch downloads remote updates without integrating them into your current branch. git pull fetches and integrates updates. The first git push -u publishes a branch and sets its upstream tracking reference; later pushes can usually use git push.

Undo changes carefully
git restore --staged [file]
git restore [file]
git revert [commit]
git reset --hard HEAD
git restore --staged [file] unstages a file while keeping its working-tree edits. git restore [file] discards uncommitted edits to that tracked file. git revert [commit] creates a new commit that reverses an earlier commit.
Warning: git reset --hard HEAD resets the index and tracked working-tree files to the current commit, discarding staged and unstaged changes. It does not remove untracked files. Check git status and save anything you need before running it.
For complete command details, see the official Git reference and the Pro Git introduction to version control.