1

I work on several git repositories with each remote repository stored on a shared network drive. My local clones of the repositories are stored in a "repos" folder on a "work location" computer connected to that network. I want to use a removable drive to transfer the current state of that entire repos folder to a "home location" computer that is not connected to the shared network. I also need to reverse the processes to take any changes back to the "work location" computer (where I can eventually push changes back to the remote repositories on the shared drive).

While there are various ways to do this, I want to know if I could make the entire repos folder into a git repository with its remote repository on the removable drive. I could then push changes from the "work location" computer to the remote repository on my removable drive, pull those change to the "home location" computer, make changes as needed, push those changes back to the remote repository on the removable drive, and then pull those changes back to the "work location" computer.

The notional structure would look something like this:

* SharedNetworkRemoteRepos (on a shared network drive at work):
├── RepoA (remote, bare git repository)
└── RepoB (remote, bare git repository)

* WorkLocationComputer
└── * repos (local clone from RemovableRemoteRepo)
    ├── RepoA (local clone from SharedNetworkRemoteRepos)
    └── RepoB (local clone from SharedNetworkRemoteRepos)

* RemovableRemoteRepo
└── repos (remote, bare git repository)

* HomeLocationComputer
└── * repos (local clone from RemovableRemoteRepo)
    ├── RepoA (local clone from SharedNetworkRemoteRepos [unreachable])
    └── RepoB (local clone from SharedNetworkRemoteRepos [unreachable])

It might be an odd idea, but is it possible? Will git allow this? Will the remote "repos" repository on the removable drive interfere in any way with all the git repositories in the repos folder (all of which belong to a completely different remote repository)? Are there other pitfalls to this method?

Thanks.

FTLPhysicsGuy
  • 1,035
  • 1
  • 11
  • 23
  • Are you looking for [submodules](https://git-scm.com/book/en/v2/Git-Tools-Submodules)? – markalex Mar 13 '23 at 11:07
  • Also, why don't you put repositories permanently on your detachable storage, and work on same repos from different computers? – markalex Mar 13 '23 at 11:11
  • I don't think I'm looking for submodules since the individual repos are cloned from a different repository than the "repos" folder that contains them. Also, I can't just use the detachable drive because the network drive is shared with other developers at work. Ultimately it's the networked repositories that constitute the master/base repos for the group. – FTLPhysicsGuy Mar 13 '23 at 22:02
  • I meant to use same local repository on your work computer and home computer. If your storage have sufficient speed, this could save you a hustle importing/exporting repo/bundle every time you want to work from home. – markalex Mar 13 '23 at 22:31
  • Oh, yes, I understand now, markalex. I forgot to mention that I've been burned before by keeping all my local repos on an external drive that failed :) My goal now is to use the external drive as a medium for transport (and it provides an added layer of backup, which is comforting). – FTLPhysicsGuy Mar 14 '23 at 23:57

2 Answers2

2

Whenever a repository needs to be "transferred" through a removable medium, it is best to use bundle (as in git bundle create) rather than bare repositories.

A bundle would limit the number of files on a removable storage device: one file represent one repository, from which can can clone or pull. (But you cannot push to it).

Meaning instead of using a global repository (which might declare the other as submodules), you only store one file per repository (a bundle) on the removable storage device, through a script which go through each of your local repository, and creates the appropriate bundle.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for the reply. I wasn't aware of the bundle concept, so I'm researching it now. I will note that one "nice" and desirable thing about my concept is that I don't even need to check in any changes to the individual repositories. I just have to check in and push/pull the overall repo folder (to/from the removable drive), and even the working state of the individual repositories should be stored and transferred. I'm not sure bundles let you do that. – FTLPhysicsGuy Mar 13 '23 at 22:08
  • @FTLPhysicsGuy You can do incremental bundle, but yes, the process is not as straightforward. – VonC Mar 13 '23 at 22:21
0

Well, after researching and a simple test, I find that it is not possible to make git treat a repository inside another "parent" repository as if it's just a normal folder to be committed/pushed/pulled.

If you're trying to commit changes and git sees a repository inside the repository you're committing, it will warn you and suggest you might want to use Submodules (which is not the behavior I'm after). It will then basically ignore the content of those "inner" repositories when performing the commit.

If anyone is curious, I ended up using a PowerShell script (we're on Windows machines) and Robocopy. However, since I use the mirror option (which can delete files and folders in the destination) and because I'm paranoid I'm going to mess up the direction one day, the script first finds all files in the destination that might be modified or deleted and creates a backup of them in another mirrored file structure. Sounds complex, but it makes me comfortable with the process.

FTLPhysicsGuy
  • 1,035
  • 1
  • 11
  • 23