Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you merge two git branches that are in different local repos/folders?

Tags:

git

I have:

folder_a/app_1.0
folder_b/app_1.1

And let's just say I'm working off of the master branch in both folders/repos.

How can I merge the branches together?

like image 641
Michael Waxman Avatar asked Aug 04 '10 04:08

Michael Waxman


People also ask

Can we merge branches from different Git repositories?

Added the source repository as a remote, by hitting the Settings button and adding the source repository. Branches from both repository now show in the branch list. I used the merge tool to merge a branch from the source repository to my new destination repository's branch. Commit the changes in my branch.

Can we merge two different repositories?

To combine two separate Git repositories into one, add the repository to merge in as a remote to the repository to merge into. Then, combine their histories by merging while using the --allow-unrelated-histories command line option.

How do I merge two local GitHub branches?

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.


1 Answers

You must pull the commits from one repository into the other, do the merge, then pull back into the first (if you want both repositories to contain all the commits).

# switch to repo A
cd folder_a

# Add repo B as a remote repository
git remote add folderb /path/to/folder_b

# Pull B's master branch into a local branch named 'b'
git pull folderb master:b

# Merge b into A's master branch
git merge b

# Switch to repo B
cd ../folder_b

# Add repo A as a remote repository
git remote add foldera /path/to/folder_a

# Pull the resulting branch into repo B's master branch
git pull foldera master:master
like image 129
Stephen Jennings Avatar answered Oct 30 '22 16:10

Stephen Jennings