Git subtree not properly using .gitignore when doing a partial clone

Looks to me like all those ignored files aren't actually in your repo - they're just leftover from your previous checkout.

Since you extracted a particular subtree from your original project, your .gitignore file is no longer present, so the files are no longer being "ignored", so you'll see them in git status. But they also aren't part of your repo; they're just sitting there.

Try using 'git clean' to clean them up.


I think this isn't anything really specific to git-subtree, you'd have the same situation if you switched between two branches and one of them generated some extra files that were in gitignore and the other wouldn't know about them... I'd say this behavior of git is rather correct, because if I add a file to gitignore, I expect it will completely ignore it and won't do anything with it - that includes also not deleting it when you move to a branch where it's not gitignored...

The possible ways you can deal with this would be:

  • add the same files also to the gitignore in subdirectory/subproject
  • do git clean before you switch branches
  • just ignore this, after all, you probably won't do much work in the branch that was generated by git subtree split other than pushing the commits outside... if you do want to work on the subproject separately, then maybe just checkout the subproject itself in another directory outside the main one.