Unable to find current origin/master revision in submodule path
Asked Answered
M

8

68

In my project (which uses git), I need to use a library, which is still in progress. I decided to create a submodule for that library, because I want to update from time to time its latest version (I don't plan to make my own change there).

I did:

git submodule add https://github.com/mb21/JSONedit.git
git commit -am 'added JSNedit submodule'
git push -u origin master
git pull origin master

Then, I did see the JSONedit folder in my local folder, and a link in my git folder online. But when I did git submodule update --remote JSONedit/, I got the following errors:

fatal: Needed a single revision
Unable to find current origin/master revision in submodule path 'JSONedit'

Does anyone know what's wrong here?

Mcmann answered 6/12, 2016 at 4:28 Comment(0)
E
78

Running this in the main repository should do the trick:

git pull --recurse-submodules

According to the other discussion, especially as @Tobu pointed out in his comment over there, if the error persists, it might be needed to first:

remove both the submodule worktree (ext/blah) and the matching folder inside the GIT_DIR (.git/modules/ext/blah)


Alternatively, you could git checkout the branch from which you want to pull while inside the submodule, and then run a git pull.

Results should be the same.

Ethnocentrism answered 6/12, 2016 at 4:39 Comment(4)
So if I just do git pull origin master in the main repository, it will not pull the submodules, right?Mcmann
Also I think it should be git submodule foreach --recursive git pull, otherwise it gives an error fatal: Couldn't find remote ref master.Mcmann
Actually, does this work for you @Mcmann git pull --recurse-submodules. This is a better approach.Ethnocentrism
it returns Fetching submodule JSONedit Already up-to-date., it seems to work...Mcmann
K
50

In my case, the problem was that Git submodule assumed there would be a branch origin/master. Instead, the submodule repository only had a branch main.

I added branch=main to the submodule definition in .gitmodules. After running git submodule sync, git submodule update --remote now works fine.

Kerley answered 10/2, 2022 at 10:4 Comment(3)
This solution worked for me. The submodule clone in a jenkins job is limited w.r.t configuration.Cartier
this is probably the most common reason at present (2022+) due to the change n default branch naming from origin/master to origin/mainVimen
My problem was that branch was set to remotes/origin/master. Changing it to just master resolved the issue.Cardinalate
T
20

I faced the same problem. It got solved. the folder in which the submodule would be stored was there. when I deleted the folder manually, it got resolved.

Thinnish answered 4/5, 2018 at 14:7 Comment(1)
I also faced this problem in a jenkins pipeline and solved it by deleting the folderNorthwest
N
11

It seems that this problem was already solved in this thread: Git submodules - pulling into a new clone of the super project. In short you should try:

# rm -rf JSONedit
# git submodule update
Ninny answered 6/12, 2016 at 4:40 Comment(0)
B
9
fatal: Needed a single revision
Unable to find current origin/master revision in submodule path
  • I face this kind of issue...
  • I fix this by updating the git version
Blackandblue answered 13/1, 2022 at 17:18 Comment(1)
Surprisingly, updating from 2.24.3 to 2.36.0 really did fix my issue.Wirewove
C
3

In my case, error log is

Unable to find current origin/HEADER revision in submodule path 'JSONedit'

This was because my multimodule not recognize submodule's checkout branch. I fix this by setting submodules branch in .gitmodules file.

In multimodule directory

git config -f .gitmodules submodule.{submodule name}.branch {branch name}
git config -f .gitmodules submodule.JSONedit.branch main

I think you probably don't have master instead main. check your branch in submodule directory by command 'git branch'.

Consignee answered 31/8, 2022 at 8:45 Comment(0)
F
2

In my case, I had deleted and cloned again a project, but the commit stored by git for my submodule did not exist in the origin repository anymore. So I did :

$ rm -rf <submodule name>
$ git clone <submodule url>
$ cd <submodule name> 
$ git checkout <whatever commit/branch you wanted>
$ cd <main project>
$ git add <path/to/submodule>
$ git commit -m "fixed my submodule"
$ git push 
Fowkes answered 29/9, 2022 at 8:27 Comment(0)
H
0

I ran into this for a Jenkins build with a submodule that indeed was using origin/main instead of origin/master. I found I was shooting myself in the foot by turning on the option to "Update tracking submodules to tip of branch". Turning it off resolved the error:

Jenkins Advanced sub-modules behavior

In my case this option is not what I actually wanted, since I use specific commit ids in the submodules.

Hypervitaminosis answered 7/6, 2023 at 22:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.