Are there any side effects to moving ".git" to a parent directory?

Viewed 50

I recently ran into an issue where I needed to expand my git repository. The first idea I had was to move .git to a new location. I went through a couple of relevant posts and I was a bit surprised no one else brought it up.

Consider the following directory structure:

 - root
 - a
   - ...
 - b
   - .git
   - ...

If I wanted to expand my repo to include everything in root, why not just move .git there? Is that a good or a bad idea? Will doing this keep my commit history intact? What are some potential side effects?

I would like to know what could potentially go wrong if I were to try this.

1 Answers

This a valid use-case. See my answer (Append project to git repository using eclipse) for a real life example where you might need to do something like this.

There's no side effect if you want everything in your parent directory to be versioned under the same repository in Git. However, if there are things that shouldn't be versioned, that's an improper use.

The user needs to be aware of what he is doing. As I said earlier that it's a legitimate use-case and this technique can be used if required to expand code under versioning.

Just make sure that you get rid of the .git folder in child directories and also add .gitignore in the parent directory to account for the changes to paths.

Related