Skip to content

Instantly share code, notes, and snippets.

@celery01
Created April 10, 2018 05:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save celery01/fa4c99125ae14d401e80b49dbc279800 to your computer and use it in GitHub Desktop.
Save celery01/fa4c99125ae14d401e80b49dbc279800 to your computer and use it in GitHub Desktop.
Merge Two Git Repos into One
Let’s keep calling the repos A and B for the moment, assume we are merging B into A, and consider the following simple example first. We’ll create a remote inside A pointing to B, then merge B’s master branch into A’s master branch.
Clone both repositories into the same directory and go into repo A:
```
$ git clone A
$ git clone B
$ cd A
```
Add a remote called B that points to the repo B (do git remote -v to view your remotes), and fetch copies of all B’s branches:
```
$ git remote add B ../B
$ git fetch B
```
To view all B’s branches that we’ve just fetched, do git branch -a. You should see B/master in the list. Now, still in repo A, create a branch called B-master in repo A that tracks B/master.
```
$ git branch B-master B/master
```
If you’re not already in the master branch, check it out, then merge B-master into A’s master.
```
$ git merge B-master
```
Assuming you have no merge conflicts, you’re done!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment