0

Is there a way to create a new repo (or branch, that would work fine as well) from an upstream project's subdirectory, while keeping merge capabilities in tact?

Example: Upstream uses a monorepo setup, with a specific subdirectory for project/xyz. I'd like to be able to separate that directory into a separate branch or repo, so the content of project/xyz would be in the root of the new branch or repo. I'll make modifications here. But I'd also want to be able to periodically merge changes that were committed upstream back into my branch or repo, while keeping the history in tact.

Ideally, I'd also be able to push my changes back to the original project as well, but I could use a patch file for that as well.

I've looked at git subtree, but from what I understand of it, it works a but like submodule, where a subdirectory of a project points to a different repo. That's not what I want (I'd have to modify the upstream project, which I cannot do, and provide all those committers with write access to my repo as well).

I've also looked at git filter-branch, but it creates new commit hashes and therefore breaks the ability to merge from upstream again.

Does anyone have a workflow for this? Is it possible with just git? Can anyone describe a script that could make this work?

Tim Stoop
  • 346
  • 1
  • 12

1 Answers1

0

If the size of the cloned project is not an issue, you might get away with the so-called "sparse checkout": basically this feature allows you to have all the history in the local clone but check out only a selected subset of the directories.

The commits to be recorded in this repo are still "normal" in the sense they will include the full state of the project. In other words, your so-called work tree — the place where the project's files are checked out will maintain limited view of the whole project.

kostix
  • 51,517
  • 14
  • 93
  • 176