πŸ“œ Git Commands

πŸ”§ Setup


git config --global user.name "Name"
git config --global user.email "you@example.com"

πŸ“‚ Repo


git init
git clone <url>

πŸ’Ύ Commit


git status
git add .
git commit -m "msg"

🌱 Branch


git switch -c feature-x
git checkout -b feature-x

πŸ”€ Merge / Delete


git merge feature-x
git branch -d feature-x

🌍 Remote


git remote add origin <url>
git push -u origin main
git pull

πŸ“œ Logs


git log --oneline --graph --all
git diff

βͺ Undo


git restore <file>
git reset --hard HEAD   # ⚠️ dangerous

πŸ”„ Common Workflows

Workflow Steps
Start New Project git init β†’ git add . β†’ git commit -m "message" β†’ git branch -M main β†’ git remote add origin <url> β†’ git push -u origin main
Clone & Work git clone <url> β†’ git switch -c feature-x β†’ git add . β†’ git commit -m "msg"
Start Feature git switch main β†’ git pull β†’ git switch -c feature-x
Submit Feature git push -u origin feature-x β†’ (Open PR / Merge Request)
Update Branch git switch feature-x β†’ git fetch β†’ git merge origin/main *(or rebase)*
Fix a Bug git switch -c bugfix-123 β†’ edit β†’ git commit -m "fix bug" β†’ git push
Tag Release git tag -a v1.0 -m "Release v1.0" β†’ git push origin v1.0
Undo Mistake git restore <file> β†’ git reset --hard HEAD