Question: I have a git project that was created from a subdirectory of another (git) project. The reason for this was that I did not want / need the complete project in order to work on a small aspect of the code. Not a good idea in retrospect.

Folders were copy-pasted, rather than using any git methodology: The new "sub-project" does not have git history that goes back beyond the time of the split.

Now, however, I want to merge the code back into the main project. With full revision history if possible. 

I've checked out the original repo to the time when the split was made. Now what do I do? I want the changes to merge on top of the existing code, which should be seemless since I've rolled back to the time I split.

However following [these instructions](http://nuclearsquid.com/writings/subtree-merging-and-you/) doesn't work:

```
$ git read-tree --prefix=path/to/subfolder/ -u remote-name/master
error: Entry 'an.xml' overlaps with 'an.xml'.  Cannot bind.

```

As the author says "Please note that the path given to the prefix option must ... be empty when executing this command."

So how can I do this?

Answer: 
[The instructions](http://nuclearsquid.com/writings/subtree-merging-and-you/) refer to a repo including another repo, ie not a *nested* repo.

That is why the path referenced by the `--prefix` option leads to an *empty* folder.

What you need to do first is:

* detach the sub-project folder into its ows git repo: see "[Detach subdirectory into separate Git repository](https://stackoverflow.com/a/17864475/6309)"
* then follow the process, with the two repos being completely separated.
While merging two branches or any branch to a master which has become obsolete after not being merged for long time. Prefer rebase over merge