3

I am developing code with another programmer. Since at the beginning I had to add new modules without modifying the existing code, I copied the source code of the other programmer and I started to develop mine. Since I always work with git, I set up a git repository and performed some commits.

Now the other programmer modified part of its code and I also had to modified some of the parts I was not supposed to modify at the beginning. Thus the situation is now the following:

  • I have a local git repo with modified files and new files
  • The other programmer has a folder (without git) with modified files

We wolud like to merge our modifications and start using git. I tried to create a bare repo in a shared folder using his code as starting point (i.e. git --bare in his previously untracked folder). Then I added this repo to my remote command using git remote add origin /path/to/local/bare/repo. Then I tried to push my changes (which can contain conflicts) with push origin master, but I geot the following message:

Everything up-to-date

However if I look at my source code and at the one in the bare repo, my changes are not present.

How can I marge two codes, one without git and the other tracked with git, into the same bare repository in order to start a shared version control?

2 Answers2

1

You might get a brilliant answer from @VonC or @torek, but off the top of my head one possibility would be to create a new branch from your Git versioned code and then use this for the merge. Into this new branch you can overwrite your files with those your friend modified. So if your current branch were master, you could take the following steps:

git checkout master                     # switch to 'master' branch
git checkout -b merge_branch            # create 'merge_branch' from 'master'
cp -r /path/to/friend/ /path/to/you/    # copy friend's files into merge branch
git commit -m 'changes from friend'     # commit this friend's work
git checkout master                     # back to the 'master' branch
git merge merge_branch                  # merge with friend's work

You will now probably have a ton of conflicts, but at least it can be handled within Git. I should also mention that this will only work if your friend has the same, or nearly the same, project file structure. If your friend has files which are in different locations, or called different things, then this approach won't work.

Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
  • 1
    Sounds brilliant enough. +1. I would make a branch from the initial commit, and `git add --work-tree=/path/to/other/coder add .`, then merge the two branches. – VonC Jul 08 '16 at 11:09
0

Step 1: Assuming that your friend did git init --bare to create a bare repo. Copy your friend's changes here. This directory acts a shared central store here on.

Step 2: Once you are sure if step 1 is complete do the following once you are done with your local commits:

1. git pull origin <branch>  --> At this point you must see if there are new files/changes
2. git merge <branch>   --> At this point you must see conflicts and modifications
3. git push origin <branch>
Swadhikar
  • 2,152
  • 1
  • 19
  • 32