0

I have on system A a (remote, read-only mounted from server B via sftp/sshfs) filesystem with data on it that needs to be pushed to a remote git repository regularly.

I was not able to find a git command that just takes the contents of a directory (and its subdirectories) and pushes it to a remote repository, without turning the local directory into a repository itself (which would require writing into the locally mounted read-only directory).

One could maybe put an overlayfs on top of the remote directory's mountpoint on server A but I read that changes on lowerdir (which will happen on server B) could occasionaly cause issues with stale file handles which in turn can sometimes only be fixed by rebooting the machine (A).

Due to the large amount of data that needs to be pushed, temporarily copying it to the local machine A and git-pushing from there is not an option.

EDIT: The files are hosted on server B in a restricted network with no access to the git repository.

7
  • 1
    Would it be possible to put the git push command(s) on the server hosting the sshfs file store? That would reduce the requirement to copy all the (changed?) data across the sshfs transport only to have it sent on its way to a remote repository Commented Jan 18, 2022 at 18:10
  • @roaima unfortunately no, that server is in a very restricted network and cannot reach the git repo. That's why I need a server in between in an area similar to a DMZ (not quite, but it has less strict security restrictions). I have added the info to the original question. Commented Jan 18, 2022 at 19:34
  • What operating system? Are you allowed to code something in Ocaml, Rust, C++, ...? Commented Jan 18, 2022 at 19:38
  • 1
    @BasileStarynkevitch The "MITM" machine is an Orcale Linux and I have access to a spacewalk server, so I could install some rust, ruby, or python interpreter. However, I'm proficient in none of them (currently learning python). Commented Jan 18, 2022 at 19:43
  • I think most of what is written is written to the .git subdirectory, so maybe (I haven't tried) you can make a directory somewhere you can write and symlink .git to that. Commented Jan 19, 2022 at 9:46

1 Answer 1

1

Git cannot push the contents of a directory to a remote server without having some sort of repository to store the data in. However, if you want to store the Git directory on a different disk or partition, you can do so.

To do that, you can set the environment variable GIT_DIR to point to the directory you'd like to use instead of .git and GIT_WORK_TREE to point to directory you'd like to use as your working tree (which would be the directory with the data you want to commit). You can then run Git commands as normal, including git init to initialize the repository, git add and git commit, and so on.

However, this will result in objects being written to the local system, which will take some disk space, even though they'll be compressed. That will probably be substantially less than the working tree, though. If that amount of disk space is too much, then unfortunately there's no way to do what you want to do, and you'll have to adopt a different approach.

1
  • So far this looks like the best solution. However, since git is tracking files and not directories, this adds some more complexity to my problem which I haven't solved yet. As the directory tracking vs file tracking issue is not the core of my question above, I will mark this as the correct answer. Commented Jan 26, 2022 at 11:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .