Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change base branch in git?

Tags:

git

Problem is described in the image as it was giving some error in the text.

enter image description here

enter image description here

like image 888
Shail_42 Avatar asked Mar 17 '16 08:03

Shail_42


1 Answers

I don't know why your question is being downvoted, because it's legitimate and very much a common mistake that beginner users make when using Git.

You accidentally created branch BR-02 from branch BR-01. One solution is to create a branch using the correct base, and then cherry-pick any commits you have made on BR-02 onto this correct branch.

git checkout BS-00      # switch to the correct branch
git checkout -b BR-03   # create the correct branch using BS-00 as a base
git cherry-pick <SHA-1> # cherry-pick the commit from BR-02

Here <SHA-1> is the hash of the commit on branch BR-02 which you wish to keep. You can find out this value by switching to BR-02 and typing git log from the terminal.

Note that this is effectively merging the commit you made on branch BR-02 into the branch BR-03, so there might be conflicts. Finally, you can delete the bad branch BR-02 since you don't need it anymore:

git branch -d BR-02     # delete the wrong branch BR-02 locally
git push origin :BR-02  # delete the wrong branch BR-02 on the remote
like image 67
Tim Biegeleisen Avatar answered Sep 30 '22 13:09

Tim Biegeleisen