29

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?

MattP
  • 489
  • 1
  • 7
  • 16
  • 1
    Have you tried `git merge --help` ? – Kenney Nov 03 '15 at 16:06
  • 1
    Possible duplicate of [Best (and safest) way to merge a git branch into master](http://stackoverflow.com/questions/5601931/best-and-safest-way-to-merge-a-git-branch-into-master) – Drenmi Nov 03 '15 at 16:33
  • I had a similar question, and I found this page useful: http://www.deferredprocrastination.co.uk/blog/2012/git-un-merge/ – Nick Alexeev Jul 08 '17 at 02:13

2 Answers2

70

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.

Actung
  • 1,438
  • 1
  • 13
  • 18
  • 5
    Its recommended practice to delete the feature branch (testBranch) after merging the code to master. @Actung, you can add this to your answer. – Muhammad Tariq Jan 17 '21 at 06:26
3

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.

h0p3zZ
  • 690
  • 3
  • 16