3

Till today, I was hosting my git repository and its submodule repository in github. And the submodule folder in all commits in the super-repository gets redirected to the correct commits in the submodule repository.

Now, I have to port the submodule repository from github to bitbucket and remove the submodule repository in github. Will this action break my commits in the super-repository? Don't the super-repositories commits store the submodule's url info in their commits?

Example scenario:

Lets say there is a commit c67061d7710e699a191965a02d9d0da341d87117 in submodule, that is referred in super-repository in many commits. I want to change that commit's reference from

githubserver/tree/c67061d7710e699a191965a02d9d0da341d87117

to

bitbucketserver/tree/c67061d7710e699a191965a02d9d0da341d87117

in all commits in the super-repository that contain's the reference to c67061d7710e699a191965a02d9d0da341d87117

I read about how to update the submodule's url in other stackoverflow questions here. But they don't clearly mention whether that url update changes references in all commits or just the commit's that follows such action.

Alanpatchi
  • 1,177
  • 10
  • 20
  • Does this answer your question? [How to change the remote repository for a git submodule?](https://stackoverflow.com/questions/913701/how-to-change-the-remote-repository-for-a-git-submodule) – Potherca Oct 05 '21 at 11:31

1 Answers1

3

The good news is that in the long run, this will work fine, because you will move all of your history from github to bitbucket and appropriately update your .gitmodules file. As soon as you do this, new checkouts and git submodule init will work fine.

The bad news is that existing checkouts will continue to use the old remote URL, so git submodule update will start to fail. To fix this, you will have to tell everyone who has checked out your repository to run git submodule sync, so as to update the remotes of the submodules to bitbucket.

user3188445
  • 4,062
  • 16
  • 26
  • so I change the `.gitmodules` file and the `git submodule init`. Will this change the submodule url of all previous commits locally? – Alanpatchi Aug 10 '18 at 17:18
  • 2
    No, you have to run `git submodule sync` to update the remotes of already initialized submodules. – user3188445 Aug 10 '18 at 17:22
  • `.gitmodules` modification, followed by `git submodule sync` will change the submodule url of all previous commits locally. But how make this change available in the remote repository, so that others can get this change in their local repositories? – Alanpatchi Aug 10 '18 at 17:27
  • 1
    You have to commit your new `.gitmodules` file. Then tell people to use `git remote set-url` to the new main repo. Then have them run a `git pull` followed by `git submodule sync`. – user3188445 Aug 10 '18 at 17:31
  • so commiting the changes in the `.gitmodules` file and pushing it, is all that is needed for the remote repository to know the whereabouts of the new submodule url, won't that mean that old commits with old `.gitmodules` file will tell the remote repository to still point out to the old submodule url in those commits, and they break, thereby? – Alanpatchi Aug 10 '18 at 17:37
  • This is why the `git submodule sync` has to be run manually. If you check out the system and appropriately run `git submodule init` and/or `git module sync` with the current version of `.gitmodules`, then your submodule remotes will be set to the new place (bitbucket). Then if you check out an old version, the `.gitmodules` file will point to the wrong place, but the module remotes will still be correct. – user3188445 Aug 10 '18 at 17:58