Ryan Kohn
Ryan Kohn

Reputation: 13509

How do I merge another developer's branch into mine?

I am relatively new to git. Our organization uses a Fork & Pull Model for managing changes to the master branch. Each developer forks the master and branches from their fork when adding new features. I keep an eye on commits that other developers are making in their own branches, and would sometimes like to merge these changes into my own branch. What steps do I take to accomplish this?

Upvotes: 124

Views: 253509

Answers (5)

Rashi Lamba
Rashi Lamba

Reputation: 11

  1. Git checkout branch1(Main branch from where you want to get the changes to your branch)
  2. git pull (branchName1)
  3. git checkout branch2(Here you want to merge all the branch 1 changes to branch2)
  4. git merge branch1

Upvotes: 1

user2513697
user2513697

Reputation:

You can also do "git pull", it'll pull the changes of all the branches.

git pull

You can run git merge into your current branch

git merge origin <branchname>

Upvotes: 28

Giorgos Myrianthous
Giorgos Myrianthous

Reputation: 39900

Let's say you are currently working on branch feature/feature_a and you want to merge the changes made in another branch called feature/feature_b to feature/feature_a. The following commands should do the trick:

git checkout feature/feature_b
git pull
git checkout feature/feature_a
git merge feature/feature_b

Upvotes: 40

Christoph
Christoph

Reputation: 28095

You first need to add the other developer repository as a remote.

git remote add otherrep uriToOtherRep

Then you fetch changes from there

git fetch otherrep

And then you merge the branch from the remote repository into yours

git merge otherrep/branchname

Happy merging!

Upvotes: 159

Michael Krelin - hacker
Michael Krelin - hacker

Reputation: 143249

once you have the branch in question in your repository as, say, anotherdev/master remote branch, you do the git merge anotherdev/master.

Upvotes: 9

Related Questions