user3428723
user3428723

Reputation:

Reverse a relationship between git branches

Say you had a git branch named branch A and you created a new branch derived from branch a named branch B.

Would it be possible through a series of commands(rebase?) to have branch A be derived from branch B? If so, how would this affect other branches already derived from the branch A? How would the commit history of the branches be affected?

To give the question context:

I have a staging branch(B) and a branch that I derive task branches from(A). I am seeing that every time I pull request A into B, when I compare B to A on GitHub, the changes that I just pull requested into B are showing up as differences. To fix this I keep having to locally merge A into B (which doesn't change any files) to get the comparison of the two to show up as having no differences. I want to reverse their relationship to fix this.

Feel free to answer this question in a way that simply solves the problem I listed here.

Visual:

I have:

   *(Feature Branches)
  /
 /
A (Developing Branch)
 \
  \
   B (Staging Branch)

I want:

B (Staging Branch)
 \
  \
   A (Developing Branch)
    \
     \
      * (Feature Branches)

Upvotes: 4

Views: 228

Answers (1)

tkruse
tkruse

Reputation: 10695

To achieve what you want you should not do pull requests from your develop branch into staging. Instead, staging branch should follow develop, and you should update the staging branch by rebasing.

Before

o < develop
|
o < staging
|
o < v0.2
|
o < v0.1

After

o < develop  < staging
|
o 
|
o < v0.2
|
o < v0.1

You can do this locally by calling

git checkout staging
git rebase develop
git push origin staging

Upvotes: 3

Related Questions