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?

1 Answer 1

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)

Sign up to request clarification or add additional context in comments.

3 Comments

uh.. so i can not work without forking.. :(..i wished if had could save the commits in original repo only.. THanks for explaination.
@AshishNegi Exactly: forking allows you to save those new commits, and for your parent repo to reference them.
yeah.. i was waiting if someone else come up with something interesting... thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.