I'm quite new to this Git thing and need a little help.
I recently created a new repo on GitHub and cloned it on my desktop. Let's call it myProject. I also have a fork in my GitHub account which I included in myProject as a submodule. Let's call this myForkOfOtherProject, which is a fork of otherProject.
So, this is the current situation:
According to GitHub:
When a repo is cloned, it has a default remote called origin that points to your fork on GitHub, not the original repo it was forked from. To keep track of the original repo, you need to add another remote named upstream.
So, my question is, how do I set the upstream to the submodule? Or am I not understanding something?
Thank you in advance.
In order to add a Git submodule, use the “git submodule add” command and specify the URL of the Git remote repository to be included as a submodule. When adding a Git submodule, your submodule will be staged. As a consequence, you will need to commit your submodule by using the “git commit” command.
Go to your fork, click on Fetch upstream , and then click on Fetch and merge to directly sync your fork with its parent repo. You may also click on the Compare button to compare the changes before merging.
Cloning a Project with Submodules If you pass --recurse-submodules to the git clone command, it will automatically initialize and update each submodule in the repository, including nested submodules if any of the submodules in the repository have submodules themselves.
When you clone a submodule into your repository, it will have its own .git/config file and its own notion of origin. Assuming that the submodule is yours (e.g. there is no third-party repository upstream of your remote) then you don't need to worry about creating an upstream remote for the submodule.
If you do 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 one the same way you did for the main repository.
cd myForkOfOtherProject
git remote add upstream git://example.com/otherProject.git
There is no namespacing conflict, because a submodule is really just a normal git repository with some additional meta-information tracked in the superproject. The superproject and the submodule do not share their .git/config files.
For all intents and purposes, you handle origin and upstream inside the submodule the same way you do for any other repository. Git commands that you run inside the submodule are independent of the superproject, which is mostly interested in tracking the submodule's current commit ID.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With