When you clone/init a repo, the .git directory is created inside your working tree. This colleague of mine wanted to check-in the source code to a legacy versioning system other than git. Normally the .git directory gets pushed as well, since it’s inside the working tree.

Normal structure
But he didn’t want to push the .git dir as well. He wanted something like this:

Required structure
If you look at the git-clone man page, there’s this option called --separate-git-dir
which lets you assign a custom directory as the .git dir. The syntax is:
git clone git://path.to.repo newdir --separate-git-dir=somedir
But in this case, my colleague didn’t want to clone again. He had local branches galore and all. So I tried out the git-clone mentioned above and checked what really happens. It turns out that git creates a file called .git
inside the working tree that looks like this:
gitdir: /home/thameera/path/to/git/dir
Gotcha! Now what we need to do is move my friend’s .git directory to a separate location and create a file called .git
that has the path to the git dir as above. It works!