add modified git submodule which is not owned

724 views Asked by At

Is it possible to add a git submodule that you modified localy but of which you are not the owner and therefore can not push to remote. Currently my repo only adds a link to the original submodule, but without my modifcations to it. But i want the full content including my modifications to be pushed to my remote repo.

I did the following so far:

cd my_repo
git submodule add git@mygithost:submodulue submodule
git submodule init && git submodule update
cd submodule
<changes, hacks>
git commit -am 'modify submodule'
cd .. && git status

> On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)

    modified:   submodule (untracked content)

no changes added to commit (use "git add" and/or "git commit -a")
1

There are 1 answers

0
phd On

i want the full content including my modifications to be pushed to my remote repo.

You cannot do that exactly because you cannot push your local changes to the original submodule. But you can work around the problem by forking the submodule.

First, fork git@submodulehost:submodulue to git@mygithost:submodulue. If you cannot fork it directly at the submodulehost clone and push: create a new empty repository git@mygithost:submodulue and do

git clone -o upstream git@submodulehost:submodulue
cd submodule
git remote add origin git@mygithost:submodulue
git push --all origin

Then use the fork as the source for your submodule:

cd ../superproject/submodule
git remote set-url origin git@mygithost:submodulue
git remote add upstream git@submodulehost:submodulue

Fix the code and push it to your fork:

git push -u origin master