7

I have one GIT repository: my_git_repo and I added a submodule: my_git_repo\submodule That is OK, now:

Is possible to add files (and change ?) to submodule but keep the tracking in the parent "my_git_repo" repository?

All I want is to be able to update the submodule but still make some changes and additions on my own.

Ideas or suggestions ? Any other way to do it nicely?

KammutierSpule
  • 109
  • 1
  • 5
  • I would like to be able to add a subfolder to a submodule, and track the subfolder in the parent repository without modifying the submodule repo. My specific use case is a third party submodule with source code for a library. I want to build the library and store the `submodule/lib` folder in the parent repo, while ignoring it in the child repo. Pretty sure this isn't supported though. – yoyo Jul 03 '20 at 16:08

1 Answers1

2

Is possible to add files (and change ?) to submodule but keep the tracking in the parent "my_git_repo" repository?

Yes, but for each new commit you will make in the submodule, you will need to:

The second step doesn't have to be done for every commit done in the submodule, but it will have to be done eventually, in order to record the next stable state of the submodule.


If the submodule is a public repo, then you need to fork it (GitHub, BitBucket), and change it remote 'origin':

cd /path/to/submodule
git remote rename origin upstream
git remote add origin /url/of/the/fork

Then you can push to the submodule repo.

To update the submodule repo with new commits coming from the original repo (that you have forked), see "Pull new updates from original Github repository into forked Github repository"

enter image description here

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • But I don't manage the "submodule" repository. It is a public repository. So I cannot push it. – KammutierSpule Aug 13 '14 at 14:08
  • @KammutierSpule but you can fork it, and then you can push. I have edited my answer to describe the process. – VonC Aug 13 '14 at 14:12
  • @VonC but if he fork it it will be separate repository and he will need to handle updtaes manually from official repo to forked one. – Michael A. Jul 27 '18 at 16:43
  • @MichaelA. Agreed: I just illustrated that in https://stackoverflow.com/a/51562274/6309 – VonC Jul 27 '18 at 16:45