39

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?

SoftTimur
  • 7,806
  • 30
  • 123
  • 245

5 Answers5

52

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.

ryenus
  • 13,960
  • 4
  • 53
  • 61
tehp
  • 3,824
  • 1
  • 23
  • 29
  • So if I just do `git pull origin master` in the main repository, it will not pull the submodules, right? – SoftTimur Dec 06 '16 at 04:45
  • 2
    Also I think it should be `git submodule foreach --recursive git pull`, otherwise it gives an error `fatal: Couldn't find remote ref master`. – SoftTimur Dec 06 '16 at 04:48
  • Actually, does this work for you @SoftTimur `git pull --recurse-submodules`. This is a better approach. – tehp Dec 06 '16 at 04:57
  • it returns `Fetching submodule JSONedit Already up-to-date.`, it seems to work... – SoftTimur Dec 06 '16 at 05:02
10

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
Community
  • 1
  • 1
M. Twarog
  • 2,228
  • 3
  • 20
  • 37
10

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.

pranav
  • 359
  • 4
  • 5
3
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
Ashish Sondagar
  • 591
  • 1
  • 4
  • 10
3

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.

F1iX
  • 403
  • 2
  • 11