Home > front end >  Is there a way to temporarily rebase a feature branch?
Is there a way to temporarily rebase a feature branch?

Time:03-09

How can I take the set of commits in my branch, and rebase them to a temporary branch, and then rebase back to main?

More details- My branch, my-branch depends on another code change feature1 that a co-worker should push soon. I don't want to wait for him, so I created temp-feature1 that contains the desired change. My plan was to rebase my-branch above temp-feature1, and rebase again to main once main contains the desired commit.

This is what I did:

During develop

git checkout main
git checkout -b temp-feature1
# commit temp changes that I want to depend on (feature1)
git checkout my-branch

And now I can develop without waiting for my college's commit.

Once feature1 is merged to main I thought I can simply do -

git checkout main
git pull
git checkout my-branch
git rebase main

And remove my temp-feature1 commit from the log, becuase it's already in main.

However, the rebase to main returned

Current branch my-branch is up to date.

And temp-feature1 commit was still there.

Is there any way to get this workflow?

CodePudding user response:

Your desired workflow is totally normal and correct! The problem is merely that you gave the wrong rebase command. You should say

git rebase --onto main temp-feature1 my-branch

This will rip just your my-branch branch commits off of temp-feature1 and shove them onto the end of main.

Before:

A -- B -- C (main) -- H -- I (temp-feature) -- X -- Y (my-branch)

After:

A -- B -- C (main) -- X -- Y (my-branch)

(PS You need to stop confusing master and main, I'm assuming that you mean main everywhere you say master. If you have both main and master you are probably in deep trouble.)

  •  Tags:  
  • git
  • Related