Change source branch

Asked

Viewed 484 times

2

Have a way to change the source branch of my current branch?

Ex.: I created a new branch from branch A, but at a certain point, I realized I should have created it from branch B and not from branch A. It has some way to change?

  • You’ve worked on this new branch?

  • That depends. What would be the impact of a B branch merge on A? A solution would be for you to merge the B branch into the new branch, which is basically the A branch plus your changes.

  • The A branch is newer and cannot be merged into the B branch (although the opposite can be done). And yes, I’ve worked on the new branch.

1 answer

3


Try it this way:

Create a new branch from branch B, we’ll call him branch D

Go back to the branch you have To as origin (Is the branch that you’ve worked on, we’ll call it C) is a reset specifying the last commit that precedes your work, then perform the git stash to temporarily save your modifications.

Enter the branch D and execute the following command, git stash pop to recover the modifications that were made in the working directory when in the branch C.

After that, resolve any conflicts, add the files in the staging area, and commit, thereby making your new branch D, has B as source and also the changes that were made when using the branch C.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.