Git Commands Cheatsheet — Complete Reference 2026

Complete Git commands reference with examples. git init, add, commit, push, pull, branch, merge, rebase, stash, and more.

Basic Git Commands

CommandDescription
git initInitialize a new Git repository
git clone <url>Clone a remote repository
git add <file>Stage file for commit
git add .Stage all changes
git commit -m "msg"Commit staged changes
git statusShow working tree status
git log --onelineView commit history (compact)
git diffShow unstaged changes
git diff --stagedShow staged changes

Remote Operations

CommandDescription
git remote add origin <url>Add remote repository
git push -u origin mainPush and set upstream
git pullFetch and merge remote changes
git fetchDownload remote changes without merging
git remote -vList remote repositories

Branching & Merging

CommandDescription
git branchList branches
git branch <name>Create new branch
git checkout <branch>Switch to branch
git switch <branch>Switch to branch (modern)
git merge <branch>Merge branch into current
git rebase <branch>Rebase onto branch
git branch -d <name>Delete branch

Stashing

CommandDescription
git stashStash current changes
git stash popApply and remove last stash
git stash listList all stashes
git stash dropDelete last stash

Undoing Changes

CommandDescription
git restore <file>Discard working directory changes
git restore --staged <file>Unstage a file
git reset HEAD~1Undo last commit (keep changes)
git reset --hard HEAD~1Undo last commit (discard changes)
git revert <commit>Create new commit undoing changes

Need These Tools as an API?

TextForge API offers 20+ developer toolkit endpoints. Free tier: 50 requests/day.

Try TextForge API Free →

Related Tools