Search code examples
gitgit-subtree

git subtree merge ignoring --prefix


I'm having a weird error with git 1.8.3 on Windows. Using git subtree, I took a file to be shared between two projects and pushed it to another repository.

So, in repo1 I did this:

# push script
git subtree split --prefix=shared-dir --rejoin --branch split
git push shared-repo split:master
git branch -D split

In both repos, shared-repo refers to the remote containing the shared code. The shared code would reside in a directory with the same name.

In repo2 I did this:

# pull script
git fetch shared-repo
git subtree merge --prefix=shared-dir shared-repo/master

What I expect it to do is to fetch the shared file and put it in repo2 under the directory ./shared-dir/. What happens is that the file is put in the root of the repository!

Moving the file to the correct folder, committing and executing something similar to the push script of repo1 results in a rejection in the push because it says that the push is not fast-forward. Running the pull script again says that everything is up-to-date.

I'm stomped and searching the internet didn't reveal anyone else having a similar problem. What's wrong and what can I do?


Update: the same happens with git 1.7.9.5 on Ubuntu 12.04 with the git-subtree script taken from the git repository some two weeks ago. I also changed the command to say --prefix=./shared-dir/ to no avail.

Interestingly, git subtree makes the shared-dir directory, but puts the shared file in the root directory instead of inside that directory.


Solution

  • The problem was that the first time adding the shared directory to the repository should be done with:

    git subtree add --prefix=... .../...