Repository mirroring - specific subpath

In our internal repository, we have both application source code and deployment files. We would like to mirror only the deployment files to another, remote git repository (and then deploy from there).
Is it technically possible in Gitlab to mirror not the whole repo (push) but just specific paths from the repo? It can’t be called mirroring then :wink: - but anyway - is it technically possible?

It is technically possible for CI job to push only the things that interest you, using reposurgeon for example.

Googled about it but not sure which functionality would be the right one to use - any hint?

I think I found it - repository splitting and merging.

1 Like

The big conundrum is that Git deals with commits, not files, and commits can touch multiple files. So what do you do with a commit that changes files both inside and outside your mirrored path(s)? That’s why it’s necessary to surgically modify the commit history either when mirroring the source commits, or when applying them to the mirror’s partial worktree. And as you say, it isn’t exactly mirroring anymore, not really.

Mirroring a repo automatically (like from a script) is usually best implemented by pushing to a bare repo, one with no working tree checked out at all. Doing that removes any chance of merge conflicts breaking your mirror updates, which will become a problem if you attempt to push commits into a repo that has a checked-out working tree… The second a commit is forced in the source repo and history gets rewritten, your push script will break due to conflicts.

OTOH, if you just want to copy a subtree of the repo somewhere, then the best tool for the job is tar. Why carry the commit history along at all?

@FeRDNYC
yes, you are right. Actually, tar or rsync would do the job.

1 Like