0

I have created a adjacent branch from another adjacent branch instead of from master branch. I have added the changes and pushed. Now I have seen that it is like

*   master commit update readme (this is how I have noticed it)
| * adj_br_2 commit blahblah
| * adj_br_1 commit blah
|/
*   master commit blblbl

Now I want to create the 2nd branch from master instead of from 1st branch.

*   master commit update readme (this is how I have noticed it)
| * adj_br_2 commit blahblah
|/
| * adj_br_1 commit blah
|/
*   master commit blblbl

Is there a way to do it without clearing and recreating the branch? In fact I need a fast way to fix it. Any suggestions?

sop
  • 3,445
  • 8
  • 41
  • 84
  • You could rebase your changes with `master` as your base instead of the other branch. Sometimes that process will require some serious manual merge conflict resolution though. – BlackVegetable Jul 28 '14 at 14:02
  • Can you please post the syntax, please? – sop Jul 28 '14 at 14:07
  • possible duplicate of [Git create a branch from another branch](http://stackoverflow.com/questions/4470523/git-create-a-branch-from-another-branch) – Joe Jul 28 '14 at 14:27

1 Answers1

5

I would just create a new one from the master:

git checkout -b new-branch master

and then if your original branch contained commits you want to take in the new branch, you can cherry-pick them:

git cherry-pick commit1 commit2 ...

and then you can remove the second adjacent branch you wanted to recreate:

git branch -d adj_br_2

In git, creating branches is pretty cheap and fast, you can afford to create new ones whenever you need to.

padawin
  • 4,230
  • 15
  • 19
  • If I do the delete part it says that `error: The branch 'adj_br_2' is not fully merged.` How to fix this? – sop Jul 28 '14 at 14:17
  • 1
    it's because it contains commits (commit hashes) which are only in it. if you are sure you will lose nothing if you delete it (eg. you cherry-picked all the commits you needed), you can force the delete with: git branch -D branch-name (capital D) – padawin Jul 28 '14 at 14:20