Git_Cheat_Sheet
Git Cheat Sheet
Quick reference for essential commands.
π Setup
git config --global user.name "Name"
Set your name.
git config --global user.email "email@example.com"
Set your email.
π Create Repository
git init
Initialize new repo.
git clone https://github.com/user/repo.git
Clone existing repo.
π Basic Workflow
git status
Check status.
git add .
Stage all changes.
git commit -m "Message"
Commit changes.
git push
Push to remote.
git pull
Pull from remote.
πΏ Branches
git branch
List branches.
git checkout -b feature
Create and switch.
git switch main
Switch branch.
git merge feature
Merge branch.
git branch -d feature
Delete branch.
π View Changes
git diff
Unstaged changes.
git diff --staged
Staged changes.
git log --oneline
Compact history.
β©οΈ Undo
git restore file.txt
Discard changes.
git restore --staged file.txt
Unstage file.
git reset HEAD~1
Undo last commit (keep changes).
git reset --hard HEAD~1
β οΈ Undo last commit (discard changes).
πΎ Stash
git stash
Save changes temporarily.
git stash pop
Restore stashed changes.
git stash list
List stashes.
π·οΈ Tags
git tag v1.0.0
Create tag.
git push --tags
Push tags.
π§ Remote
git remote -v
View remotes.
git remote add origin url
Add remote.
git fetch
Download changes (no merge).
π Rebase
git rebase main
Rebase onto main.
git rebase -i HEAD~3
Interactive rebase.
π Quick Reference Table
| Task | Command |
|---|---|
| Init | git init |
| Clone | git clone url |
| Add all | git add . |
| Commit | git commit -m "msg" |
| Push | git push |
| Pull | git pull |
| Status | git status |
| Log | git log --oneline |
| Branch | git checkout -b name |
| Merge | git merge name |
| Stash | git stash |
| Diff | git diff |
π Related
#git #cheatsheet #reference #quick