I have a git repo in /foo/bar/baz
with a large commit history and multiple branches.
I now want /foo/qux
to be in the same repo as /f
This adds to Walter Mundt's accepted answer. I would have rather commented on his answer, but I don't have the reputation.
So Walter Mundt's method works great, but it works only for one branch at a time. And after the first branch, there may be warnings that require -f to force the action through. So to do this for all branches at once, simply add "-- --all" to the end:
git filter-branch --commit-filter '
tree="$1";
shift;
subtree=`echo -e 040000 tree $tree"\tsrc" | git mktree`
git commit-tree $subtree "$@"' -- --all
And to do this for specific branches, add their names to the end instead, although I can't imagine why you would change the directory structure of only some of the branches.
Read more about this in the man page for git filter-branch. However, please notice the warning about possible difficulties pushing after using such a command. Just make sure you know what you're doing.
I'd appreciate more input on any potential problems with this method.