Shafiul
Shafiul

Reputation: 2910

Two different Git repo in same directory

I want to maintain two different git repos. The repos should stay in the same root directory. How to achieve it?

What I'm want is: to manage two repositories that differ slightly. Can I have two completely different repositories in the same directory?

Upvotes: 15

Views: 15789

Answers (2)

Andrew
Andrew

Reputation: 1

I solved this problem, which git doesn't seem to provide a good solution to, by not using git to solve it. I used a directory junction to link a new subfolder to a subfolder of the parent folder (i.e. linking a child folder to an "uncle folder"). Example in Command Prompt for Windows Vista and up:

cd CurrentFolder/
mklink /J "LinkedFolder" "../TargetFolder"

will cause LinkedFolder to point to TargetFolder (note the quotes). Example file structure I would then use:

  • root/
    • TargetFolder/
      • shared files
    • CurrentFolder/
      • LinkedFolder/

"POSIX-compliant" operating systems seem to use ln or ln -s for this functionality.

It works excellently (note: the following is from my own Windows 8.1 testing):

  • the LinkedFolder does not exist before calling mklink
  • when you make the link, anything you do to the files in either the TargetFolder or the LinkedFolder will reflect in the other, as they are one and the same
  • if you delete the link (LinkedFolder), nothing happens to the actual target folder (TargetFolder)
  • if you delete the actual target folder (TargetFolder), the link will remain active (it does not get deleted); if you then try to access the link, you will simply get an error; if you recreate the actual target folder (TargetFolder) again, the link will continue to work as before!

See also:
NTFS Junction Point
NTFS Symbolic Link
Symbolic Link

Upvotes: 2

Adam Dymitruk
Adam Dymitruk

Reputation: 129744

You can achieve this by adding using one of these two options on the git command itself:

git --work-tree=where/my/code/is --git-dir=some/path/to/my/.git status

This would allow you to have 2 separate repos share the same working folder.

However you should be able to get what you need by using one repo with multiple branches and perhaps only push certain branches to multiple remotes.

Upvotes: 13

Related Questions