Showing posts with label Version Control. Show all posts
Showing posts with label Version Control. Show all posts

How to Rename a Local Git Branch (git branch -m Explained)

Quick answer: to rename the branch you're currently on:

git branch -m new-name

To rename a branch you're not currently on:

git branch -m old-name new-name

How to Undo git add Before You Commit (Unstage Files Safely)

Quick answer: run git restore --staged <file> (modern Git) or git reset <file> (works everywhere) to unstage a file you added by mistake, before it's committed.

git pull vs git fetch: What's the Difference? (With Diagram)

Quick answer: git fetch downloads new commits and updates your local "remote-tracking" branches (like origin/main) without touching your working files. git pull does the same fetch, then immediately merges (or rebases) those changes into your current branch. In short: git pull = git fetch + git merge.

How to Delete a Git Branch Locally and Remotely (Step-by-Step)

Quick answer:

git branch -d branch_name          # delete local branch
git push origin --delete branch_name   # delete remote branch

How to Undo the Last Git Commit Locally (3 Safe Methods, 2026 Guide)

Quick answer: to undo your last local Git commit but keep the changes on disk, run git reset HEAD~1. To undo the commit and throw the changes away completely, run git reset --hard HEAD~1. Neither command touches a remote unless you push afterward.