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
Rather than create a new repository, move what's in your current repository into the right place: create a new directory bar
in your current directory and move the current content in (so your code is in /foo/bar/bar
). Then create a baz
directory next to your new bar
directory (/foo/bar/baz
). mv /foo /foo2; mv /foo2/bar /foo; rmdir /foo2
and you're done :).
Git's rename tracking means that your history will still work and Git's hashing of content means that even though you've moved things around, you're still referencing the same objects in the repository.
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.