Reputation: 13
I have a project with a third party submodule of which I am not a contributor of.
I had to make changes to some of it's files, namely some project files, so that I could target a different platform (original project targeted mono, while I have switched to dotnet core), yet I still want to be able to merge the latest changes of the original submodule repository.
Using a normal setup of just having the project as a submodule, I cannot successfully clone my project because git will not find the commits I've made in the original repository:
Server does not allow request for unadvertised object <my_commit_id>
Fetched in submodule path <submodule>, but it did not contain <my_commit_id>
I would like to do something similar to the command git submodule update --remote --rebase
in which the changes I've made to the submodule will be written on top of the new ones from the original remote, but I want to be able to commit the changes I made to my super project so that when I clone the repository the changes will be applied on top of the submodule.
Is there any way to do something like that?
Upvotes: 1
Views: 162
Reputation: 488183
A submodule is a Git repository. It's just a Git repository that some other Git—the superproject—will git clone
for you and then git checkout
some particular commit (as a "detached HEAD" in the submodule).
Anyone who clones the superproject will at some point run git submodule update --init
. That will have the superproject run git clone
to obtain the submodule Git repostiory. Any commits you made in your clone are ... well, in your clone. They're not in any other clone. So you'll have to give everyone on the Internet—or at least, everyone who might git clone
your superproject—access to your clone of that submodule.
If you don't want to give the entire Internet access to your laptop—and you probably don't—you must stop keeping the only copy of the submodule repository on your laptop. In other words, you need a public-access version of the submodule.
Let's suppose the submodule you cloned yesterday is https://github.com/someone/sub.git
. Your laptop clone of this submodule, file://path/to/sub.git
, has no generally-accessible-from-the-Internet URL (file://...
on my laptop refers to my files, not yours). So what you need to do is make, on GitHub or wherever, your fork of that submodule: https://github.com/bodhi_daruma/sub.git
or whatever that may be.
Now that you do have a public-access version of sub.git
, you can send your submodule Git commits to that repository. You'll probably want to make your submodule commits, on your laptop, in a branch, rather than using the "detached HEAD" mode that your superproject set. See existing questions about how to do that. Then you'll git push
the commits you made in your submodule on your laptop, to the Git on GitHub (or wherever it is you are keeping this).
Now you'll want to have your superproject Git refer to https://github.com/bodhi_daruma/sub.git
, or whatever the URL is, rather than https://github.com/someone/sub.git
. That is, when people clone your superproject, that clone will direct their superproject Git to git clone
your fork of the submodule.
The only other real alternative is to propose to whoever maintains the submodule you're using that they incorporate your commits into their (GitHub-or-whatever) repository. That probably also involves using the fork feature on GitHub or Bitbucket or wherever this submodule repository resides.
Upvotes: 0
Reputation: 1324188
A submodule is a repository: you can replace it with a fork, which can:
upstream
remote which reference the original repositoryupstream
commits (git fetch uptream
)submodule update --remote --rebase
, with your origin/master
of your fork being rebased on top of local master
, which was reset to upstream/master
)Upvotes: 1