Image for 'This Week I Learned' blog post featuring tips on managing Git branches including renaming and syncing with remote changes.

Dive into this edition of 'TWIL,' our weekly expedition into the ever-evolving landscape of tech wisdom. This week, Emily enlightens us on Git, sharing savvy techniques for Managing and Updating Branches with Rewritten History. Discover how to align your local branch with remote changes, seamlessly renaming branches to preserve your work or to freshen up your repository for that crystal-clear PR.

Managing and Updating Branches with Rewritten History

There are times where you may need to overwrite your local branch to match a remote - maybe the branch was cherry-picked or rebased by another person to fix conflicts, etc.

# Update local branch 
# - Retrieve the current version of the branch
git fetch origin <branch_name>
# - Force your local version of the branch to match the new version you fetched
git reset --hard origin/<branch_name>

If you need to force-update a local branch but don't want to lose your history locally, you can rename the branch first:

# - Rename the branch you currently have checked out
git branch -m <new-branch-name>

# - Rename a branch by name
git branch -m <old-branch-name> <new-branch-name>

Alternatively, you can push a local branch to a different name. Often, I'll checkout a new branch with the clean-prs prefix and cherry-pick to that. That way, my original local branch remains intact.

# Push a branch as a different name
# I usually read the ":" as "as"
# e.g. "push clean-prs/feature/new-thing as feature/new-thing"
git push clean-prs/feature/new-thing:feature/new-thing
  • Git
Emily Morehouse's profile picture
Emily Morehouse

Cofounder, Director of Engineering

Related Posts

AWS logo centered over dark blue stylized map of Europe with concentric radar-style rings emanating from Germany, representing the AWS European Sovereign Cloud infrastructure launch for EU data sovereignty and GDPR compliance
January 26, 2026 • Frank Valcarcel

AWS Launches European Sovereign Cloud

AWS launched a physically separate cloud infrastructure in Europe with EU-only governance, zero US dependencies, and over 90 services. Here is what organizations in healthcare, finance, and government need to know about the sovereign cloud and how to evaluate it for their compliance strategy.

MCP (Model Context Protocol) logo — a stylized white interlinked letter mark — centered on an abstract background of flowing purple and orange gradient waves, representing AI connectivity and data integration.
November 25, 2025 • Frank Valcarcel

Anthropic’s Model Context Protocol: The Standard for AI Tool Integration

A year after launch, Anthropic’s Model Context Protocol has become the universal standard for connecting AI agents to enterprise tools. Backed by OpenAI, Google, Microsoft, and the Linux Foundation. Here’s what developers need to know.

Let's work together

Tell us about your project and how Cuttlesoft can help. Schedule a consultation with one of our experts today.

Contact Us