I have lost count of the number of times I have referred myself to my own Tweet to remind myself how to "lift and shift" a feature branch from one trunk to another. Therefore, I have decided to immortalise this content on my own blog!

Some organisations I see have multiple trunks, and for this example, I'll use a production and a development branch. Let's say you have a branch called feature, which is based off development.

diagram showing current git branch tree

Given this current tree, you are asked to move your feature branch to the production branch, so the new tree should look like this:

diagram showing desired git branch tree

The right Git command for this is (with an optional -i to make an interactive rebase, which I highly recommend!):

git rebase -i --onto <new-trunk> <old-trunk> <your-branch>

So, in our example above, the command to run would be:

git rebase -i --onto production development feature

Need some help? I specialise in helping development teams to write high quality software.

Get in touch with me to see how I can start helping your team today: