Essential Git and GitHub Commands for Open Source Developers

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:

  • 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 reset only when you're absolutely sure β€” especially in collaborative environments.

βœ… Best Practices Roundup

CommandBest Used When
cloneStarting from a remote repo
branchCreating a separate feature or bug fix
rebaseSyncing your branch before PR
cherry-pickMoving a fix from one branch to another
stashTemporarily saving work mid-task
pull --rebaseKeeping history linear while updating
log --onelineVisualizing commit tree
resetCleaning 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.