DEV Community

Cover image for Rebasing off a repo root
Thomas Hartmann
Thomas Hartmann

Posted on • Originally published at thomashartmann.dev on

3 1

Rebasing off a repo root

Ever had to change something about all the commits in a git repo before pushing it to a remote? As in from the very first commit in a repo? Maybe you’ve started a repo locally and when you’re ready to push it, you realize that you’ve used the wrong author or messed up the format of the commit messages; or maybe you just want to squash those first few commits into a single concise package.

In these situations, my first response is to do to an interactive rebase (git rebase -i). Usually when I’m rebasing, though, I’m in a project that has an upstream and where I’m rebasing off a specific commit or branch. For situations where you don’t have a commit to rebase off, but you want to rebase the entire history or at least the very first commit: What do you do?

The answer, my friend, is that you pass the --root option:

git rebase -i --root

That’ll let you pick, reword, edit, squash, fixup, exec, drop, label, reset, or merge all of your commits from the ‘dawn of time.’

Have fun!

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay