git submodules with others repos

I want to use in repo A some changes of repo B. B does not belong to me. A is mine.

I did :

git submodule add -- external/elm-mdl

i.e. B is elm-mdl

I had already cloned the repo, hence -- in above command.

I then run :

cd external/elm-mdl
git checkout v9
git checkout v9-my
.. make some changes and commit.
cd ../..

Back in A's root

git config -f .gitmodules submodule.external/elm-mdl.branch v9-my

└─ $ ▶ cat .gitmodules 
[submodule "external/elm-mdl"]
    path = external/elm-mdl
    url =
    branch = v9-my

Now, how can I keep these commits saved as i can not update or create a branch in remote repo B i.e. elm-mdl ?

I can not update the remote :

ashish @ 7567 ~/work/be_autonomous (master) 
└─ $ ▶ git submodule update  --remote --merge
fatal: Needed a single revision
Unable to find current origin/v9-my revision in submodule path 'external/elm-mdl'
ashish @ 7567 ~/work/be_autonomous (master) 

Can I save these commits in my original repo A?
Or what are the alternatives?

1 answer

  • answered 2017-08-12 09:43 VonC

    git config -f .gitmodules submodule.external/elm-mdl.branch v9-my

    That means external/elm-mdl will try to pull/update the v9-my branch: when you do modification in that submodule, you need to be in that branch (and to push your new commits to the remote repo of that submodule)

    cd external/elm-mdl
    git checkout -b v9-my
    # work
    git add .
    git commit -m "new commit in v9-my branch"
    git push -u origin v9-my

    If you cannot push to the current repo, fork that repo (make it your own) an push there.

    Then, when you have modified and committed and push in the submodule, you still need to go back to the parent repo, add, commit and push there too: it will save the new SHA1 of the submodule (its gitlink, a special entry in the index of the parent repo)