Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 747
Irfy Avatar asked May 26 '16 13:05

Irfy


People also ask

Is using git submodules a good idea?

Git submodules may look powerful or cool upfront, but for all the reasons above it is a bad idea to share code using submodules, especially when the code changes frequently. It will be much worse when you have more and more developers working on the same repos.

How do I manage git submodules?

Use the git submodule update command to set the submodules to the commit specified by the main repository. This means that if you pull in new changes into the submodules, you need to create a new commit in your main repository in order to track the updates of the nested submodules.


1 Answers

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.

like image 116
Irfy Avatar answered Sep 22 '22 15:09

Irfy