2

I had a project, called 'A' which had quite a long Git history. At some point in the project 'A' switched IDE's, and unknown to the developer it disconnected from the git repo, and created a new local repo, lets call that 'B'.

'B' has had several commits, but is still based off the most recent commit of 'A', which has been unchanged since the diversion.

Now I'd really like to bring 'B' back into 'A', but keep its commits if possible. Could anyone lend some advice on how to achieve this?

edit: was marked as a duplicate of this however, in that example the 2nd repo is not a mirror of the first, instead it is a seperate module which wants to be added to the project, whereas in this example it is intended to replace the original.

xceph
  • 996
  • 2
  • 11
  • 25

1 Answers1

1

Follow the next steps:

  1. cd path/to/A
  2. git remote add fork https://github.com/someone/B (replace the url with the B url)
  3. git pull fork
  4. git checkout master (replace master with the branch name where you want to merge the B commits into)
  5. git merge fork master (replace master with the B branch)

If you will have conflicts, you will have to fix them, but since A is not changed you will probably not have any conflicts. Summarizing, you can do everything in one command:

 git pull <url-of-repo-B> master

(again, replace master with the source branch)

Ionică Bizău
  • 93,552
  • 74
  • 254
  • 426
  • Few issues: $ git remote add fork ~/Projects/B $ git pull fork --all fatal: fetch --all does not take a repository argument $ git checkout A Already on 'A' Your branch is up-to-date with 'origin/A'. $ git merge fork master merge: fork - not something we can merge $ git merge fork merge: fork - not something we can merge – xceph Oct 05 '15 at 12:28
  • @xceph Try `git pull fork` instead. Also, you may find the last command useful. Run this in your `A` repository: `git pull master`. – Ionică Bizău Oct 05 '15 at 12:41