4

I have a large C project under git. Someone else has the same C project but he's not using git.

Both of us started from the same baseline, but I simply did a git init / git add . and started using git.

I'd like to merge my git managed changes into the other branch and init git on his project's folder so we're both synced and use git.

How would you do this in git?

Greg
  • 16,540
  • 9
  • 51
  • 97
Arjor
  • 979
  • 1
  • 8
  • 12
  • Possible duplicate of [How do I clone into a non-empty directory?](https://stackoverflow.com/questions/2411031/how-do-i-clone-into-a-non-empty-directory) – Tobias Kienzler Aug 15 '17 at 05:34

2 Answers2

5

Your friend should $ git init, $ git add . and $ git commit -a his code.

Both of you should have the same remote repository : $ git remote add origin <your-repository-url> (with GitHub it looks like https://github.com/username/repository.git)

Your friend has to $ git pull origin master (it will merge the remote branch to his local one)

He just has to $ git push -u origin master so you can $ git pull and it should be ok

plucile
  • 306
  • 3
  • 4
  • The friend can also run `git fetch origin master:arjor` to get OP's contribution in a separate branch, and at their convenience then `git merge arjan` or `git rebase arjan` (rebasing of course only if not already `push`ed...) – Tobias Kienzler Aug 15 '17 at 05:36
1

First clone your repo into a blank directory.

Then, in the new repo, create and checkout a new branch for you friend's work. The branch point should be the last commit where you both had the same source (probably your initial commit).

You then copy his sources into the new tree. Git status/diff should now show the modifications he made.

Do git commit on that branch, and you should have one repo with both forks of development.

Do git merge master to merge your work (which is on the "master" branch) into your colleagues new branch. Have fun resolving the conflicts, commit, and you're done.

If you want the changes back in your own repo, then do you can pull or fetch from his repo, using an ssh:// URL, if you have ssh access to the machine, or file:/// if you can see it directly.

ams
  • 24,923
  • 4
  • 54
  • 75