-1

I downloaded a module from github. But instead of using the github repository, I initialized my own and pushed all the code to my own bitbucket remote repository with one "initial commit".

But I would like to use the github repo, so that it is easier to keep it up to date. So I opened .gitmodules and changed the URL of the repo, made a commit and pushed.

But if I execute git clone myrepo_url.git and then execute git submodule --init --update --remote then everything is fine, but the module where I changed the URL.

> fatal: Needed a single revision, unable to find commit of
> origin/master in Submodul-path 'app/code/EthanYehuda/CronjobManager'

Thats maybe because my old repository used master as the main branch and the github repository uses 1.x.

.git/modules/app/code/EthanYehuda/CronjobManager/config:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        worktree = ../../../../../../app/code/EthanYehuda/CronjobManager
[remote "origin"]
        url = https://github.com/Ethan3600/magento2-CronjobManager.git
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "1.x"]
        remote = origin
        merge = refs/heads/1.x

.gitmodules

[submodule "app/code/EthanYehuda/CronjobManager"]
        path = app/code/EthanYehuda/CronjobManager
        url = https://github.com/Ethan3600/magento2-CronjobManager.git

How can I fix this so that the error does not show if I clone the project?

Black
  • 18,150
  • 39
  • 158
  • 271

1 Answers1

1

The solution is to add branch information to the file .gitmodule

[submodule "app/code/EthanYehuda/CronjobManager"]
        path = app/code/EthanYehuda/CronjobManager
        url = https://github.com/Ethan3600/magento2-CronjobManager.git
        branch = 1.x

Now there were no errors

(Git 2.22, Q2 2019, has introduced

git submodule set-branch --branch aBranch -- <submodule_path>)

So always lookup the main branch first and add it with the above command, after calling

git submodule add <git-url.git> <name-of-module>
Black
  • 18,150
  • 39
  • 158
  • 271
  • 1
    Or you can remove `--remote` from `git submodule --init --update --remote`, eg use `git submodule --init --update` and it won't require a branch configuration for the submodule. – Motin Mar 28 '21 at 08:22