Configure upstream flow to a submodule (or enable the GitHub plug as a submodule)

I am brand new to this git stuff and need a little help.

I recently created a new repo on GitHub and cloned it on my desktop. Let me call it myProject . I also have a plug in my GitHub account, which I included in myProject as a submodule. Let me call this myForkOfOtherProject , which is the otherProject fork.

So this is the current situation:

Graph of the current state of repos

According to GitHub :

When cloning a repo, it has a remote origin by default, which points to your fork on GitHub, and not the original repo that it was forked from. To track the source repo, you need to add another remote with the name upstream .

So my question is: how to set upstream in a submodule? Or am I not understanding something?

Thanks in advance.

+7
source share
2 answers

Submodules

When you clone a submodule into your repository, it will have its own .git / config file and its own concept of origin. Assuming the submodule is yours (for example, there is no third-party repository above your remote), you do not need to worry about creating an upstream remote for the submodule.

If you need to create an upstream remote for your submodule, it's easy enough. Just cd into the top level directory of your submodule and give it the same way as for the main repository.

 cd myForkOfOtherProject git remote add upstream git://example.com/otherProject.git 

There is no name conflict because the submodule is just a regular git repository with some additional meta information tracked in the superproject. Superproject and submodule do not share .git / config files.

For all purposes and tasks, you process the origin and upstream within the submodule in the same way as for any other repository. The git commands that you run inside the submodule are independent of the superproject, which is mainly interested in tracking the current submodule commit id.

+7
source
 git remote add upstream git://github.com/otherUser/otherProject.git 

will only work if the git protocol (by default, port 9478) is authorized.
I couldn’t do it from work (and I don’t even mention ssh addresses: ssh is also blocked from working with remote addresses "outside the local network").

 git remote add upstream https://github.com/otheruser/otherProject.git 

will work (providing a few additional settings )

Note: creating an upstream in your submodule repository ( described as CodeGnome , upvoted) is useful for you update that submodule with the latest of otherProject

 cd myForkOfOtherProject git fetch upstream # or fetch + merge: git pull upstream 

It will not be used to return to another project (if you fork it, perhaps because you are not a co-author).
If you make any evolution directly to myForkOfOtherProject , you will need to commit it, then go to the parent repo and commit it (see "The true nature of submodules ."). And do a pull request if you want the initial otherProject supporting to take this into account.

+2
source

All Articles