Arjor
Arjor

Reputation: 1049

clone git repo to a non-empty folder

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?

Upvotes: 4

Views: 3496

Answers (2)

plucile
plucile

Reputation: 316

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

Upvotes: 5

ams
ams

Reputation: 25599

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.

Upvotes: 1

Related Questions