1

I have a subrepo in an ext/[subrep] directory that I want to track a different branch.

I have followed the instructions for switching subrepo branches at https://github.com/ingydotnet/git-subrepo/wiki/FAQ however, it does not seem to be working.

First, since the code in the subrepo and its parent are not production ready code, I want this subrepo to be on an independent branch.

For better reference tracking, I created a new branch, then merged all of the existing work from the previously tracked branch into the new branch.

If I follow the instructions explicitly, that is without specifying the exact directory where the subrepo is located, I get a new directory instead simply changing the branch reference in the .gitrepo file.

After having merged my existing work with the new branch, if I then specify the remote URL, the branch I want to track, and the existing directory, the clone simply tells me that the subrepo is up-to-date without changing anything - even with the --force flag specified.

What I have had to do is to

  1. git subrepo clean ext/[subrepodir]
  2. git rm -r -f ext/[subrepodir]
  3. physically delete ext/[subrepodir] (cloning the subrepo here without first deleting the directory gives the directory not empty error even with the --force flag.
  4. git commit
  5. git subrepo clone [remoteURL] ext/[subrepodir] --force -b new_branch

The result of the above is that the subrepo is properly tracking the new branch. However, from the FAQ it seems like I should not have to go through all of this just to switch the branch that the subrepo is tracking.

Is this a bug?

wiyosaya
  • 95
  • 9

2 Answers2

0

I never used submodule before, and come across an artical which may resolve your problem, pls read it, it is well written. About switching the default branch in a submodule, run the following command:

# "DbConnector" is the submodule name, and "stable" is the expected branch of the submodule
git config -f .gitmodules submodule.DbConnector.branch stable

Reference artical: https://git-scm.com/book/en/v2/Git-Tools-Submodules

MadHatter
  • 301
  • 3
  • 12
  • Thanks for the reference, however, Git subrepo and Git submodule are two different commands. https://metacpan.org/dist/App-Spec/view/examples/pod/subrepo.pod I am not sure that this would work for Git subrepo, and I lack the time to test this with Git subrepo. There are a couple of work-arounds, however and they seem to be the answer other than they both seem like more work than should be necessary. https://github.com/ingydotnet/git-subrepo/issues/184 https://github.com/ingydotnet/git-subrepo/issues/194 – wiyosaya Jan 11 '23 at 15:18
  • 1
    Thanks for the info, now I see there are several concepts: submodule, subtree and subrepo, I will learn more about them first. – MadHatter Jan 12 '23 at 10:56
0

It looks like this is possible using the syntax:

git subrepo <subrepo_name> pull -b <branch_name>

I needed to first invoke (in at least some situations):

git subrepo clean <subrepo_name> 

https://github.com/ingydotnet/git-subrepo/issues/336#issuecomment-663901849

kcoul
  • 150
  • 5
  • Thanks. I will give it a test when I have the opportunity to do so. – wiyosaya Mar 30 '23 at 17:07
  • Finally got back to this. I created a branch in the repo, however, it has no current commits and is at the head with master/develop. I then did a "git subrepo clean with the subrepo name as the parameter after having done a "git subrepo clean --all" Using the syntax "git subrepo pull -b " I get an error is not a command. using the syntax "git subrepo pull -b " I get an error that says "couldn't find remote ref " – wiyosaya Apr 28 '23 at 15:58
  • 1
    So a quick follow up - it looks like the branch I had created in the master repo had not been properly pushed to that repo. Once I pushed it (even though it does not yet have any commits), I then executed a git subrepo clean " to be sure any artifacts that might have existed were cleaned, and then I executed another git subrepo pull --branch=" and the command completed successfull. So the key appears to be that the branch must exist and have been pushed to the master repository. Thanks for your help and inspiring me to figure it out. – wiyosaya Apr 28 '23 at 16:13