1

There is a A project and the A project has a submodule S
A
|-S
|-B
|-C

A repo: git@github.com:benjamin/A.git
S repo: git@github.com:owner/S.git

To contribute some bug fix, I forked the A repository and cloned it.

$ git clone git@github.com:benjamin/A.git

and then to download a submodule S I commanded

$ git submodule init
$ git submodule update

Okay, the code tree are made well, and I fixed the bug at a file in A and a file in S.
To commit and push the two files,

$ cd S
$ git add modified_file
$ git commit -a -m 'submodule commit'
$ git push

But the push is not work.

ERROR: Permission to owner/S.git denied to benjamin.
fatal: The remote end hung up unexpectedly

Should I also fork S repository either? How do you do in this case?

Benjamin
  • 10,085
  • 19
  • 80
  • 130

1 Answers1

2

Yes, a submodule is a git repo in itself.
You need to

  • fork both repo,
  • clone them both,
  • make a symlink between A and S locally (just for your code to compile, ie don't bother with the submodule status of S locally)
  • commit in both local repo your changes and push them to your respective fork
  • make two pull requests (one for A, one for S)

Only the maintainer of A and S will be able to:

  • apply your pull request in S and commit
  • apply your pull request in A
  • commit in A, recording the new SHA1 of S (submodule) and the changes in A.

Mark Longair mentions that you can:

  • clone your fork of A
  • git submodule init
  • git submodule update (that will clone S to the right SHA1, but with 'S' as a remote, not 'forked-S')
  • cd S
  • git remote set-url origin <SSH-url-of-fork-of-S>
  • git checkout -b my-changes-to-S: make a branch in order to record your local modification, and to avoid being in a detached HEAD mode.
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • There's no need for a symlink, surely? He can just `cd S` and `git remote set-url origin ` and `git checkout -b my-changes-to-S` – Mark Longair Jun 29 '12 at 10:03
  • @MarkLongair I suppose after a `git submodule init/update`? I have included your suggestion in the answer. – VonC Jun 29 '12 at 12:55