2

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 -- https://github.com/debois/elm-mdl.git 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 = https://github.com/debois/elm-mdl.git
    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?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Ashish Negi
  • 5,193
  • 8
  • 51
  • 95

1 Answers1

1
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)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • uh.. so i can not work without forking.. :(..i wished if had could save the commits in original repo only.. THanks for explaination. – Ashish Negi Aug 12 '17 at 10:02
  • @AshishNegi Exactly: forking allows you to save those new commits, and for your parent repo to reference them. – VonC Aug 12 '17 at 10:03
  • yeah.. i was waiting if someone else come up with something interesting... thanks – Ashish Negi Aug 12 '17 at 13:51