1

I've currently a git repository that I uploaded to GitHub. When I was to my school, I wanted to develop the code and downlad the repository (without the ".git" folder, so I just got the code itself).

I did many changes and committed multiple times, but now I'm home I want to merge the new commits I made on the new folder on the old one.

Here is an example :

Original folder

Initial commit [with no code]
Commit 1
Commit 2

New folder

New initial commit (with the code of commit 2)
Commit 3
Commit 4
Commit 5

Now I want to add Commit 3, Commit 4 and Commit 5 to the original folder. How can I do it ?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
ClementNerma
  • 1,079
  • 1
  • 11
  • 16
  • Maybe I'm missing something, but is not as simple as moving the new folder to the original folder? – Mikel San Vicente Dec 09 '16 at 18:26
  • No, because the commits I made on the original folder are not done in the new folder. In the new one, which contains the code after `Commit 2`, I initialized a **new** git repository and made commits in it. Now I want to add the commits I made on the new repository to the original one. – ClementNerma Dec 09 '16 at 18:28

1 Answers1

1

You can fetch one repo in the other, and then if you want merge them

A merge would only be possible since git 2.9 if the branches has no common history

git merge --allow-unrelated-histories a b

In your case, you could directly pull from the second repo:

git remote add second_repo /path/to/second/repo
git pull second_repo master

That will be enough to get the commits from the second repo back into the first one.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • The method you gave doesn't work, when I perform the `git pull` command it says me `fatal: refusing to merge unrelated histories`. Also, when I do `git merge --allow-unrelated-histories second_repo master`, it shows me that there are conflicts in the code, but it doesn't seem to be any conflict in files... – ClementNerma Dec 09 '16 at 19:30
  • @ClementNerma git status will list you the files to fix – VonC Dec 09 '16 at 19:37