Git Branch Commands Every Beginner Forgets: Delete Remote Branches, Rename Files, and Rebase Like a Pro

Key Takeaways

- Use git push origin --delete <branch> to remove remote branches from the command line
- Always use git mv instead of regular mv to preserve file version history
- Pull with --rebase to avoid messy merge commits on your master branch
- Configure your default branch name globally with git config --global init.defaultBranch main
Read in Short
Most Git tutorials cover the basics and leave you hanging when things get weird. These seven tips cover the gaps: deleting branches on remote repos, renaming files without losing history, rebasing to keep your commits clean, and setting up your default branch name. Bookmark this one.
Look, we've all been there. You learn git add, git commit, git push, and you think you've got this version control thing figured out. Then someone asks you to delete a remote branch and suddenly you're Googling frantically while pretending to type something important.
I've been collecting these beginner Git tips for a while now, and honestly? Even developers with years of experience mess these up. So let's fix that.
Deleting Remote Branches From the Command Line
Deleting a local branch is pretty straightforward. You've probably done it a hundred times:
git branch -d <branch>The lowercase -d flag is the safe option. Git checks if the branch has been merged first. If you want to live dangerously and force delete regardless of merge status, you use the big D:
git branch -D <branch>But here's where people get stuck. How do you delete that branch on GitHub or GitLab without clicking around in the web UI?
git push origin --delete <branch>That's it. One command. No need to open your browser, navigate to branches, find the delete button. The kicker? Most people don't even know you can list remote branches from the terminal:
git branch --remotePro Tip
After deleting remote branches, other team members might still see stale references. They can clean those up with: git fetch --prune
Renaming Files Without Destroying Your History
This one drives me crazy because I've seen senior developers make this mistake. Here's the scenario: your coworker John moves a script to a subdirectory and changes two lines of code. Now Git thinks the original file was deleted and a completely new file was created. All the version history? Gone. Poof.

The next time someone runs git blame, your name shows up as the author of the entire file. Even though you only touched two lines.
Git gets confused when you rename or move a file AND change its contents at the same time. It can't figure out that it's the same file. The solution is dead simple:
git mv <source> <destination>Instead of the regular mv command, use git mv. This tells Git explicitly that you're moving the file, not deleting one and creating another. Your commit history stays intact. Your coworkers won't hunt you down. Everyone's happy.
If you're learning Git best practices, you'll want to read about other habits that can make or break your code quality.
Why You Should Rebase When Pulling Master
Okay, this one's a bit more advanced but it'll save you from a really annoying situation.
When you push to a remote branch, your local branch needs to be ahead of the remote. That's called the fast-forward rule. On feature branches, you can force-push if things get messy. But on master? You should never force-push to master. Ever.
So how do you keep your local master ahead when you're pulling updates from the remote? You rebase:
git pull --rebase origin masterIf you don't use the --rebase flag and you have local changes, Git might create a merge commit on your local repo. And then you're stuck. You can't push to master because of the merge commit, and you definitely shouldn't force-push.
What's a Rebase?
Rebasing rewrites your local commits on top of the latest remote commits. Instead of creating a merge commit that says 'merged branch X into Y', your commits appear as if they were made after the latest remote changes. Cleaner history, fewer headaches.
Setting Your Default Branch Name
Here's some context that trips up a lot of beginners. Until a couple years ago, every Git repository had a default branch called master. It was just how things worked.
Then there was a push to change this terminology, and GitHub was the first major platform to react. They switched the default to main. Git itself kept master as the default for a while, but added an option to change it.
So if you initialize a repo locally with git init, you might get master as your default branch while GitHub expects main. Confusing, right?
Here's how you set your preferred default branch name globally:
git config --global init.defaultBranch mainNow every new repo you create will use main instead of master. No more mismatched branch names between your local machine and GitHub.
Quick Reference: All Commands in One Place
| Task | Command |
|---|---|
| Delete local branch (safe) | git branch -d <branch> |
| Delete local branch (force) | git branch -D <branch> |
| Delete remote branch | git push origin --delete <branch> |
| List remote branches | git branch --remote |
| Move/rename file | git mv <source> <destination> |
| Pull with rebase | git pull --rebase origin master |
| Set default branch name | git config --global init.defaultBranch main |
Why These Commands Matter
I know what you're thinking. These seem like small things. And yeah, individually they are. But Git is one of those tools where small mistakes compound into massive headaches.
That merge commit you accidentally created on master? Now you're spending 30 minutes trying to figure out how to fix it without breaking anything. The file you renamed without git mv? Your team lead is asking why you rewrote an entire module when you only fixed a typo.
- Deleting remote branches keeps your repo clean and your branch list manageable
- Using git mv preserves blame history so the right person gets credit (or blame)
- Rebasing when pulling prevents merge commit nightmares
- Setting your default branch avoids confusion between local and remote repos
Ready for something more advanced? This practical guide breaks down quantum computing without the buzzwords.
The Bottom Line
Git has a reputation for being confusing, and honestly, it deserves that reputation sometimes. The documentation is dense, the error messages are cryptic, and there are about fifteen ways to do everything.
But once you memorize these handful of commands, you'll handle 90% of the situations that trip up beginners. Print them out, stick them on a Post-it, save them somewhere. Your future self will thank you the next time you need to delete a remote branch at 4 PM on a Friday.
And hey, maybe don't be like John. Use git mv.
Frequently Asked Questions
What's the difference between git branch -d and git branch -D?
The lowercase -d is the safe option that checks if the branch is merged before deleting. The uppercase -D force deletes the branch regardless of merge status.
Can I recover a branch after deleting it from remote?
If someone still has the branch locally, they can push it back up. Otherwise, you might be able to recover it using git reflog if you're quick, but it's tricky.
Should I always use --rebase when pulling?
For your main/master branch, yes. For feature branches it depends on your team's workflow. Some teams prefer merge commits for clearer history of when features were integrated.
Source: DEV Community
Manaal Khan
Tech & Innovation Writer
Related Articles
Browse all
Google Workspace API Updates March 2026: New Calendar API, Chat Authentication, and Maps Changes
Google just dropped Episode 29 of their Workspace Developer News, and there's a lot to unpack. From a brand new secondary calendar lifecycle API to deprecation warnings for Apps Script authentication, here's everything developers need to know about the March 2026 platform updates.

Zig for Legacy C Code: How to Modernize Infrastructure Without a Risky Full Rewrite
A new blueprint from Zeba Academy shows developers how to surgically replace fragile C components with Zig modules. Instead of risky full rewrites, this approach lets you swap out problematic code piece by piece while keeping your battle-tested infrastructure intact.

Claude Skills vs Commands: When to Use Each for AI-Powered Coding Workflows
Claude's Skills and Commands look similar on the surface since both use markdown files, but they work completely differently. Skills run automatically based on context while Commands need explicit /invocation. Here's how to pick the right one for your coding workflow.

DualClip macOS Clipboard Manager: The Only Tool That Uses Dedicated Slots Instead of History
DualClip v1.2.6 just dropped with a major stability fix and Homebrew support. After analyzing 57 clipboard managers, the developer found every single one uses history. DualClip takes a radically different approach with three fixed slots and zero disk storage.
Also Read

3 Ways to Soundproof Your Home Theater Without Ruining Décor
A surround sound system powerful enough to 'shift tectonic plates' can turn neighbors into enemies. A tech journalist shares practical fixes that reduced subwoofer noise without compromising audio quality or room aesthetics.

Krafton's ChatGPT Scheme to Dodge $250M Bonus Backfires
Subnautica 2 launches this week as Steam's most-wishlisted game. Its release follows a bizarre legal saga where Krafton's CEO allegedly used ChatGPT to plot avoiding a $250 million payout to the studio founders he then fired.

TCL CSOT Unveils 5,131ppi Display for XR Glasses
TCL's display division showed off a 0.28-inch Micro LED panel at Display Week 2025, claiming the world's highest pixel density. The company also revealed a 1,700ppi OLED for VR headsets.