Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merging multiple branches with git

Tags:

git

merge

rebase

I have 2 local branches called "develop" and "master"; they are similar. On my company's server there's one "main" repo (production) and several branches that were made by other developers:

 $ git branch -a * develop   master   remotes/origin/HEAD -> origin/master   remotes/origin/some-test   remotes/origin/feature1   remotes/origin/feature2   remotes/origin/master 

How can I merge remotes/origin/feature1 and remotes/origin/feature2 into my local "master" branch, copy that all into "develop" and start working with actual code in my "develop" branch?

like image 243
Chvanikoff Avatar asked Mar 13 '11 20:03

Chvanikoff


People also ask

How do I merge all branches at once?

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. Note: git merge merges the specified branch into the currently active branch.

How do I merge branches in GitHub?

In GitHub Desktop, click Current Branch. Click Choose a branch to merge into BRANCH. Click the branch you want to merge into the current branch, then click Merge BRANCH into BRANCH. Note: If there are merge conflicts, GitHub Desktop will warn you above the Merge BRANCH into BRANCH button.

How do I merge two console branches?

To do a merge (locally), git checkout the branch you want to merge INTO. Then type git merge <branch> where <branch> is the branch you want to merge FROM. Because the history of master and the history of make_function share common ancestors and don't have any divergence descendents, we get a "fast-forward" merge.


1 Answers

  1. git checkout master
  2. git pull origin feature1 feature2
  3. git checkout develop
  4. git pull . master (or maybe git rebase ./master)

The first command changes your current branch to master.

The second command pulls in changes from the remote feature1 and feature2 branches. This is an "octopus" merge because it merges more than 2 branches. You could also do two normal merges if you prefer.

The third command switches you back to your develop branch.

The fourth command pulls the changes from local master to develop.

Hope that helps.

EDIT: Note that git pull will automatically do a fetch so you don't need to do it manually. It's pretty much equivalent to git fetch followed by git merge.

like image 66
Cameron Skinner Avatar answered Sep 23 '22 01:09

Cameron Skinner