diff --git a/bitbake/lib/bb/fetch2/gitsm.py b/bitbake/lib/bb/fetch2/gitsm.py
index f7f3af7212..e37be055eb 100644
--- a/bitbake/lib/bb/fetch2/gitsm.py
+++ b/bitbake/lib/bb/fetch2/gitsm.py
@@ -23,6 +23,7 @@ import copy
 import shutil
 import tempfile
 from   bb.fetch2.git import Git
+from   bb.fetch2 import URI
 from   bb.fetch2 import runfetchcmd
 from   bb.fetch2 import logger
 from   bb.fetch2 import Fetch
@@ -93,6 +94,11 @@ class GitSM(Git):
                     newud.path = os.path.normpath(os.path.join(newud.path, uris[m]))
                     uris[m] = Git._get_repo_url(self, newud)
 
+                # Double-encode before handing over to git to handle spaces in URLs
+                double_encoded_uri = URI(uris[m])
+                double_encoded_uri.path = double_encoded_uri.path_quoted
+                uris[m] = str(double_encoded_uri)
+
         for module in submodules:
             # Translate the module url into a SRC_URI
 
