Git commands
Updated 2026-02-08
Frequently used Git commands and options for daily workflow.
Basics
git initInit repo.
git clone <url>Clone a repository.
git statusWorking tree status.
git add <path>Stage file(s).
git add .Stage all changes.
git commit -m "msg"Commit with message.
Branching
git branchList branches.
git branch <name>Create branch.
git checkout <name>Switch branch.
git switch <name>Switch branch (newer).
git checkout -b <name>Create and switch.
git merge <branch>Merge into current branch.
Remote
git remote -vList remotes.
git fetch originFetch from remote.
git pullFetch and merge.
git push origin <branch>Push to remote.
git push -u origin <branch>Push and set upstream.
Undo / history
git log --onelineShort log.
git diffUnstaged changes.
git restore <file>Discard changes in file.
git reset --soft HEAD~1Undo last commit, keep changes staged.