Whether you're just starting out or have already made your first PR, mastering these GitHub commands will turn you from a beginner contributor into a confident, efficient open source developer.
This guide focuses on the real Git commands that matter in day-to-day open source contribution — not just clone and commit, but also rebase, stash, cherry-pick, and more. Each command is paired with real use cases so you know when and why to use it.
📥 1. git clone
What it does:
Downloads a remote GitHub repository to your local machine.
Command:
git clone https://github.com/username/project-name.git
Real Use Case:
You're contributing to a project for the first time. After forking the repo, you clone it locally so you can start editing and making changes.
✅ Pro Tip: Always clone your fork, not the original repo, so you can push to it directly.
🌱 2. git branch
What it does:
Creates and manages branches — a safe space to make changes without touching the main code.
Commands:
git branch # List branches
git branch feature-x # Create new branch
git checkout feature-x # Switch to branchOR shorthand:
git checkout -b feature-x
Real Use Case:
You’re fixing a bug or adding a new feature. You create a branch like fix-navbar-bug to isolate your changes before submitting a PR.
✅ Always create a new branch for each contribution — never push directly to
main.
🔁 3. git rebase
What it does:
Moves or "replays" your branch commits onto another base branch. Useful to clean up history or update your branch before merging.
Command:
git checkout feature-x
git fetch origin
git rebase origin/main
Real Use Case:
You made your PR, but the main branch got new commits. To avoid merge conflicts, you rebase your branch on top of the latest main.
⚠️ Rebase rewrites history — only do it on branches you haven’t shared yet, or be cautious.
🎯 4. git cherry-pick
What it does:
Takes a specific commit from one branch and applies it to another.
Command:
git cherry-pick <commit-hash>
Real Use Case:
You fixed a bug on a dev branch, but now realize the same fix is needed on main. Use cherry-pick to bring just that commit over.
✅ Great for applying hotfixes without merging an entire branch.
🧳 5. git stash
What it does:
Temporarily saves changes you don't want to commit yet. Great when you need to quickly switch context or pull new changes.
Commands:
git stash # Stash uncommitted changes
git stash pop # Reapply the latest stash and delete it
git stash list # View all stashes
git stash apply # Reapply without deleting stashReal Use Case:
You're halfway through editing a file but need to quickly switch to another branch to fix a build error — stash your changes, switch branches, then pop them back later.
✅ Stash = life-saver during context switching.
🔄 6. git pull --rebase
What it does:
Updates your local branch with changes from the remote, keeping a clean linear history (no merge commits).
Command:
git pull --rebase origin main
Real Use Case:
You’ve been working on a branch, and before pushing or rebasing, you want the latest main changes locally in a clean way.
✅ Most modern teams prefer
pull --rebaseoverpullto keep history tidy.
👀 7. git log --oneline --graph
What it does:
Shows a clean and visual view of your commit history.
Command:
git log --oneline --graph --all
Real Use Case:
You want to visualize branching history, see where your branch is relative to main, and understand the commit flow.
✅ Super helpful before rebasing or reviewing a complicated history.
❌ 8. git reset (Bonus, use with caution)
What it does:
Lets you undo changes in different scopes — from unstaging to deleting commits.
Use Cases:
Soft reset: Uncommit, keep changes
git reset --soft HEAD~1
Hard reset: Danger zone — undo everything to a specific commit
git reset --hard <commit-hash>
⚠️ Use
resetonly when you're absolutely sure — especially in collaborative environments.
✅ Best Practices Roundup
| Command | Best Used When |
clone | Starting from a remote repo |
branch | Creating a separate feature or bug fix |
rebase | Syncing your branch before PR |
cherry-pick | Moving a fix from one branch to another |
stash | Temporarily saving work mid-task |
pull --rebase | Keeping history linear while updating |
log --oneline | Visualizing commit tree |
reset | Cleaning up commits (carefully!) |
💡 Summary
Mastering these Git/GitHub commands isn't just about being a better contributor — it's about being a clean, professional, and efficient developer in any team or open source project.
Start with the basics, but don’t fear commands like rebase, stash, or cherry-pick. They’ll soon become second nature as you contribute more and dive deeper.
Join the conversation! Your thoughts help the community grow.