Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I merge a branch into a master in github?

Tags:

git-merge

I created a repo and github, and pushed my files to it. Then had a colleague create a branch and make changes. I want to merge the branch to master.

What steps do I take?

like image 632
MattP Avatar asked Nov 03 '15 16:11

MattP


People also ask

Can you merge a branch of a branch to master?

Once the feature is complete, the branch can be merged back into the main code branch. First we run git checkout master to change the active branch back to the master branch. Then we run the command git merge new-branch to merge the new feature into the master branch.

How do I merge a branch into main?

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.

Can you merge a branch into master multiple times?

Merging a branch multiple times into another works fine if there were changes to merge. Show activity on this post. Actually yes you totally can, when you merge again it will bring over any commits that don't exist on production.


2 Answers

Please do following set of commands in order to merge with the master, Assuming that you are in branch testBranch and you want to merge the changes with the master,

First checkout to master branch,

git checkout master

Now pull the latest changes in master,

git pull origin master

Merge with the testBranch

git merge testBranch

Push the changes to master

git push origin master

That's it, you are done.

like image 165
Actung Avatar answered Nov 23 '22 09:11

Actung


You could also just create a pull request.

If there are no merge conflicts its easier.

If there are merge conflicts:

git fetch origin
git checkout {branch}
git merge master

Afterwards you have the merge conflict on your branch and you can resolve it.

git add .
git commit -m "{commit message}"
git push

And you have resolved the merge conflict and can merge the pull request onto the master.

Hint: With squash and merge the whole branch is committed as one commit onto master.

like image 37
h0p3zZ Avatar answered Nov 23 '22 08:11

h0p3zZ