Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge parent branch into child branch

Tags:

I'm using bitbucket and sourcetree and I've done this:

I have a develop branch. From this branch I have created a feature branch.

After creating I have fix some errors on develop branch and push it to this branch only.

How can I have these fixes in the feature branch? I think I have to merge develop branch into feature branch but I'm not sure because I'm new in git and I don't want to do something wrong that makes me lose develop branch. but now I want to have these fixes on my feature branch.

What do I have to do?

like image 994
VansFannel Avatar asked Aug 07 '15 09:08

VansFannel


People also ask

What happens to child branch when parent is merged?

Child branches are not affected by merges of their parent branches. Branches are basically just a concept for human users, git only sees commits.

Can I merge a branch into another branch?

To merge branches locally, use git checkout to switch to the branch you want to merge into. This branch is typically the main branch. Next, use git merge and specify the name of the other branch to bring into this branch. This example merges the jeff/feature1 branch into the main branch.

How do you rebase a child branch with the parent branch?

The solution is to use git rebase --onto after rebasing the first branch. This will rebase all commits of feature2 that follow the old head of feature1 (i.e. F ) onto the new head of feature1 (i.e. F' ).


2 Answers

You want to bring changes from development branch to feature branch. So first switch to feature branch and merge development branch into it. In case you want the commits from develop branch too, use the non fast forward merge --no-ff approach. Else do not use --no-ff.

git checkout feature git merge --no-ff develop 

As you are merging develop branch into feature branch, stay assured that develop branch will remain untouched. You may get merge conflicts in feature branch which can be easily solved following the steps on this link: http://softwarecave.org/2014/03/03/git-how-to-resolve-merge-conflicts/

like image 113
Aditya Kadakia Avatar answered Oct 27 '22 01:10

Aditya Kadakia


Yes you can merge or preferably rebase develop in your feature.

git checkout feature git rebase develop 

If you get merge errors you can skip rebase by

git rebase --skip 

or solve the conflicts and continue with (after adding your solution):

git rebase --continue 

Also see this question

like image 21
LcKjus Avatar answered Oct 27 '22 00:10

LcKjus