Skip to main content

Command Palette

Search for a command to run...

🧠 Essential Git Commands Cheat Sheet

Updated
3 min readView as Markdown
🧠 Essential Git Commands Cheat Sheet
M

I’m a backend software engineer with over a decade of experience primarily in Java. I started this blog to share what I’ve learned in a simplified, approachable way — and to add value for fellow developers. Though I’m an introvert, I’ve chosen to put myself out there to encourage more women to explore and thrive in tech. I believe that by sharing what we know, we learn twice as much — that’s precisely why I’m here.

Whether you're new to Git or want to keep your workflow sharp, here’s a handy list of commands that cover the most common — and a few life-saving — actions.

Clone the repo

git clone <repository-url>

🔍 See What's Going On

git status

Shows what's changed, what's staged, and what's untracked.

git log --oneline

View commit history (detailed or summarized).

➕ Stage & Commit Changes

git add <file>     # Stage a single file
git add .          # Stage everything
git commit -m "Your message here" Creates a commit with your staged changes.

💡 Git Tip: Think of Git as a three-step process:
1️⃣ Working Directory – where you make edits
2️⃣ Staging Area – where you select what to commit
3️⃣ Repository – where your project history lives

Staging gives you control over what gets committed, so you can group related changes together before saving them permanently.

🔄 Stash Changes

git stash -m "WIP: login bug"   # Save changes with a label
git stash list                  # View stashes
git stash apply [stash@{id}]    # Reapply a specific stash

💡 Git Tip: Need to switch tasks but don’t want to commit your work yet?
Use git stash to save your changes temporarily and return to a clean working state.
Later, use git stash apply to get your work back.

🛠️ Pro Tip: Use git stash list to see all stashes, and git stash drop to delete one you no longer need

🌿 Branching

git branch                    # List branches
git branch feature-xyz        # Create a new branch
git checkout feature-xyz      # Switch to it
git checkout -b feature-xyz   # Create and switch to a new branch in one line
git switch feature-xyz        # Newer switch syntax

⬇️⬆️ Sync with Remote

git pull          # Pull latest changes
git push          # Push local commits

# Sets the upstream tracking branch when pushing for the first time
git push -u origin [branch-name]

# Force-push your local branch — use with caution! Ideal after a rebase:
git push --force

🔧 Undoing Mistakes

git restore <file>            # Discard local changes
git restore --staged <file>   # Unstage a file

🧨 Life-Saving Commands

Pull the latest from main and rebase your current branch in one single step:

git fetch && git rebase origin/main

💡 Git Tip: Keep your branch up-to-date and avoid merge commits by rebasing onto the latest main. Perfect for clean history before a PR.

Remove commits but keep the changes:

💡 Need to rewrite history? --soft lets you uncommit changes but keeps them staged so you can tweak and recommit.

git reset [commit-hash] --soft

Pull a file from another branch to modify it locally:

💡 Want just one file from another branch? This command pulls it into your current branch without switching context.

git checkout other-branch -- path/to/file

Cheat Sheets

Part 1 of 1

More from this blog

Code Like a Woman

40 posts

Code, learnings, and experiences from a Latina in tech.