Home > Software engineering >  Remote git branch changed to `main' but `master' in local submodule
Remote git branch changed to `main' but `master' in local submodule

Time:07-15

I have a submodule repo, added to my project when the remote called its main branch master. Now they renamed it to main and when I try to pull I get error:

Your configuration specifies to merge with the ref 'refs/heads/master'
from the remote, but no such ref was fetched.

I could nuke the submodule and re-add it, I suppose. But is there a more elegant solution?

CodePudding user response:

There is at least one .gitmodules file in your repository, and it should have something like

 [submodule "foo"]
    path = bar
    url = https://github.com/baz/foo
    branch = master

If branch is not there, it defaults to master. You can add branch = main. If it's there, change it to branch = main. Commit the changes in .gitmodules and run git submodule update --remote to update the submodule.

As @torek mentioned, we can also use git submodule set-branch -b main -- foo to update the submodule's branch. Note that it's not foo/, just foo without the slash, for the submodule name.

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

  • Related