git: How do you add an external directory to the repository?

If I need to do something like that I would normally move that external file or directory into my git repo and symlink it's original location to the new one.

mv /home/some/directory /htdocs/directory
ln -s /htdocs/directory /home/some/
git add ./directory

I use this technique when I am developing a plug-in for an application that I want to keep under version control but have to store in a specific location.


I had the same error... Googled it to death... not much came out.

Christian's answer worked :

git --work-tree=/ add /home/some/directory

But then "work-tree" got me going. I grep'd all Git docs and came up with core.worktree.

I used

git config --global core.worktree /

And voila! I can now add from any directory in the system. I don't know if it will cause problems any other places, but I'll try to update as I go along.


git --work-tree=/ add /home/some/directory