Git Command Cheat Sheet
Configuration
-------------
git config --global user.name "Your Name"
git config --global user.email "you@example.com"
git config --list
Repository Setup
----------------
git init
git clone <repo-url>
Staging & Snapshots
-------------------
git status
git add <file>
git add .
git reset <file>
Commit Changes
--------------
git commit -m "Your message"
git commit -am "Commit + add"
Branching
---------
git branch
git branch <name>
git checkout <name>
git checkout -b <name>
git switch <name>
git switch -c <name>
git branch -d <name>
Merging & Rebasing
------------------
git merge <branch>
git rebase <branch>
Fetching & Pulling
------------------
git fetch
git pull
git pull origin <branch>
git pull --rebase origin <branch>
Pushing
-------
git push
git push origin <branch>
git push -u origin <branch>
git push origin --delete <branch>
History & Logs
--------------
git log
git log --oneline --graph --all
git show <commit>
Undo & Revert
-------------
git restore <file>
git checkout -- <file>
git reset HEAD~1
git revert <commit>
Diff & Compare
--------------
git diff
git diff --staged
git diff <branch1>..<branch2>
Remote Repos
------------
git remote -v
git remote add origin <url>
git remote remove origin
Stashing
--------
git stash
git stash pop
git stash apply
git stash list
Submodules
----------
git submodule add <repo> <path>
git submodule update --init --recursive
Advanced / Cleanup
------------------
git cherry-pick <commit>
git reflog
git clean -fd
Publishing New Repo to GitHub
-----------------------------
git init
git add .
git commit -m "Initial commit"
git branch -M main
git remote add origin <repo-url>
git push -u origin main
Common Git Workflows
--------------------
# Create & Push New Branch
git checkout -b feature/login
git push -u origin feature/login
# Sync with Main
git checkout main
git pull origin main
git merge feature/login
# Delete Branch After Merge
git branch -d feature/login
git push origin --delete feature/login