1

I was handed over a project by a friend. No versioning was used. I needed to make changes so I created a git repository from this project directory with Sourcetree. I use this versioning for local use only. There is no remote. I just like the idea that every change I make is nicely watched and can be reverted any time. I've made many changes.

Now my friend comes up with a new copy of the project. He also made many changes.

What is the best way to merge these changes?

  • Do I clone my repository in a separate directory overwrite the project files and push them to my original one?
  • Do I simply overwrite my working copy?
  • Do I create and checkout a branch and overwrite those files?

(I realize I will always need to manually check every 'change' and decide to include this or not.)

ProllyGeek
  • 15,517
  • 9
  • 53
  • 72
user63457
  • 591
  • 2
  • 7
  • 18
  • Did I misunderstand your question? Do you mean that your friend is not planning on using git and she/he delivers changes to you as a snapshot of her/his whole project directory? – Jay Dec 11 '13 at 09:11

2 Answers2

1

EDIT

In case your friend is not using git and delivers you her/his whole project directory, a good way is to use folder diff to create a patch and apply that patch into your git repository


previous answer

Assuming your friend serves his git repository locally, you could use git remote to add his git repository as a remote to your local one. Then you could pull/review/merge changes from his repository into your one. Your friend can do the same on his machine. This way you will be able to synchronize your changes directly, without any servers in between. Downside is that both of your computers must be online when git push and git pull commands are executed.

Git is decentralized VCS so it downloads all repository commits directly on to your machine.

Having said that, its very common for teams to use git repository hosting for convenience purposes. That hosted git repository acts as a quasi-centralized one. You can push and pull changes to it at any time without waiting for your friend to be online. As your team grows bigger, its a lot more convenient for 10 developers to have one central remote repository, rather than 9 individual remotes to each of the other developers.

Once you have added a new remote branch to your git repository, you could use git branch command to switch branches.

How to add remote in Sourcetree

git-remote man

git-branch man

git book

Community
  • 1
  • 1
Jay
  • 3,445
  • 2
  • 24
  • 29
  • Maybe my question wasn't completely clear, but by saying 'no versioning was used' I tried to say my friend did not use any kind of versioning. – user63457 Dec 11 '13 at 09:12
0

Bit overdue, but might be helpful for future generations...

A much cleaner way is to checkout a branch 'friend' at the commit that is supposed to contain his original (that's probably the first commit in the rep), unmodified contribution.

In that branch, store his contribution, commit, and then merge that branch into your 'master'.

Once you understand this mechanism, take a look at the subtree merge mechanism

axd
  • 626
  • 5
  • 13