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 branch
OR 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 stash
Real 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 --rebase over pull to 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:
Hard reset: Danger zone β undo everything to a specific commit
git reset --hard <commit-hash>
β οΈ Use reset only 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.