Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Moving Branch from Master to Another Branch in Git

Tags:

git

I usually use subversion, and am getting used to git.

I cloned a copy of a remote repository to my localhost, and then created a new branch, which we'll call "myNewBranch'. However, I created that branch off of master when it should have been a sub-branch of "DEVELOPMENT".

Here are the steps I took:

  1. git clone remoteURL localhost
  2. git checkout -b mynewBranch (should have switched to DEVELOPMENT first)
  3. git add {whatever files I changed}
  4. git commit
  5. git push origin myNewBranch

Here is what the hierarchy should look like:

Master ---> DEVELOPMENT ---> myNewBranch

Here is what it currently looks like: Master--->myNewBranch

How can I rectify this?

like image 443
Bad Programmer Avatar asked Jan 02 '23 15:01

Bad Programmer


2 Answers

Simply rebase your new branch on top of development.

git checkout myNewBranch
git rebase development
like image 193
Igal S. Avatar answered Jan 05 '23 00:01

Igal S.


I accepted Igal S.'s answer, however instead of rebase I used cherry-pick.

I had a single commit, and my commit was the very last one, so I checked out DEVELOPMENT into a new branch:

git checkout -b myNewBranch DEVELOPMENT

And then ran cherry-pick on my commit (had to get the hex checksum)

git cherry-pick <hex checksum>

And then reconciled conflicts.

After that, I commited changes from cherry pick, and then deleted my old branch on both local and master. I'm still new to git, so don't take my word on this as a solution, but if might be helpful if other people run into the same problem.

like image 35
Bad Programmer Avatar answered Jan 05 '23 01:01

Bad Programmer