■ Git & GitHub Cheatsheet
1. Git Basics
• `git init` → Initialize a new Git repository
• `git clone ` → Clone (download) a repo
• `git status` → Show current repo state
• `git add ` → Stage a file
• `git add .` → Stage all changes
• `git commit -m 'msg'` → Save staged changes with a message
2. Branching & Switching
• `git branch` → List branches
• `git branch ` → Create a new branch
• `git checkout ` → Switch to branch
• `git checkout -b ` → Create & switch to branch
• `git switch ` → Alternative to checkout
• `git merge ` → Merge into current branch
3. Remote Repos (GitHub)
• `git remote add origin ` → Link repo to GitHub
• `git remote -v` → Show remotes
• `git push origin ` → Push commits
• `git push -u origin ` → Push & set upstream
• `git pull origin ` → Fetch & merge latest
• `git fetch` → Download changes only
4. Tags (Versions)
• `git tag` → List tags
• `git tag ` → Create tag
• `git tag -a v1.0 -m 'msg'` → Annotated tag
• `git push origin v1.0` → Push tag
• `git push origin --tags` → Push all tags
5. Undoing Mistakes
• `git reset ` → Unstage file
• `git reset --hard ` → Reset to commit (■ irreversible)
• `git revert ` → Undo commit safely
• `git restore ` → Discard local changes
6. Merge Conflicts
• Conflict markers appear (<<<<<<<, =======, >>>>>>>).
• Edit & decide what to keep.
• `git add ` → Stage fixed file.
• `git commit -m 'Resolved conflict'` → Save resolution.
7. Open Source Contribution Workflow
• 1. Fork repo → copy project
• 2. Clone → `git clone `
• 3. Create branch → `git checkout -b feature`
• 4. Commit changes → `git commit -m 'msg'`
• 5. Push branch → `git push origin feature`
• 6. Open Pull Request on GitHub
8. CI/CD Basics
• CI → Auto tests on every push/PR
• CD → Auto deployment after merge
• GitHub Actions → define `.github/workflows/ci.yml`
9. Pro Tips
• `git log --oneline --graph` → Pretty history
• `git diff` → Show unstaged changes
• `git stash` → Save temp work
• `git stash pop` → Restore work
• `git pull --rebase` → Clean history
• `git cherry-pick ` → Apply specific commit