git

How to change the parent branch in git

Imagine the scenario, you’ve created a branch from master, made all the changes you need, and find that instead of deploying those changes right away, you’ll need to push them to a server other than production. That is, you would need this branch to have its origin in another branch, maybe the develop branch ? The process is very simple and straightforward.

imagine the situation. You are on master (git checkout master) and you create a branch, based on it (git checkout -b new-branch). Add the files, do your job and commit.

If you’re going to see it in a visual program, like gitk you’ll see that its parent is master.
The trick, quite simple actually, is to stay on the ‘wrong’ branch, and rebase to the right branch (git rebase develop) that way you are changing the parent of that branch. If necessary, go with the interactive mode, with git rebase -i develop but so far I haven’t needed that…

That way its parent will be develop (which in this case, came from master)

Leave a Reply

Your email address will not be published. Required fields are marked *


Notice: ob_end_flush(): failed to send buffer of zlib output compression (0) in /home/samu/public_html/blog/wp-includes/functions.php on line 5107