diff --git a/apt/gitrepo.proxy.in b/apt/gitrepo.proxy.in
index 29791b951d7d5aa472b3e77bb949a40f1c06c3db..a6ea882cbe76a2d48b6655df89df7ffed186f579 100644
--- a/apt/gitrepo.proxy.in
+++ b/apt/gitrepo.proxy.in
@@ -169,7 +169,7 @@ sub Clone()
     if (system("$GIT cat-file -e ${refspec}:.gitmodules") == 0) {
 	# Need the branch name for switch.
 	my $branch;
-	if ($refspec =~ /^refs\/heads\/(\w+)/) {
+	if ($refspec =~ /^refs\/heads\/([-\w]+)/ || $refspec =~ /^([-\w]+)$/) {
 	    $branch = $1;
 	}
 	else {