Irfy
Irfy

Reputation: 9587

git: manage multiple remotes in a submodule

My team uses a publicly available github hosted project as a submodule in our main project. We would like to manage our own patches against that project, without pushing upstream, but then we can't share those patches unless we have a mirror where we push our private branch.

Assuming we have the mirror, our submodule needs two remotes: one where we fetch upstream changes from, and one where we push merges with our patch branch. How can we store the information about the remotes with the submodule (or with the superproject), so that, every member of the team can trivially perform an upstream update, without having to git add remote upstream ...github...project.git.

We intend to solve the problem by writing a shell script to automate the process and a file for storing the upstream remotes, but is there a git way of doing this?

May be related, but I don't see a proper solution: git add remote in submodule

Upvotes: 13

Views: 3043

Answers (1)

Irfy
Irfy

Reputation: 9587

The current ansatz is this:

  • For each submodule that needs to be managed in the above-described way, have a submodule/.gitupstream file store the url
  • With a simple shell script:
    • update the submodule's upstream remote from this file
    • git fetch upstream
    • git checkout known submodule patch branch (possibly from .gitmodules submodule..branch)
    • git merge upstream/master (or whichever refspec)

Then manually:

  • git push origin (the mirror containing our patch branch)
  • commit changed submodule and push in the superproject

I'd like to see a better, possibly git built-in solution though.

Upvotes: 4

Related Questions