Skip to content

Commit 7b2ecd8

Browse files
artagnongitster
authored andcommitted
push: fail early with detached HEAD and current
Setting push.default to current adds the refspec "HEAD" for the transport layer to handle. If "HEAD" doesn't resolve to a branch (and since no refspec rhs is specified), the push fails after some time with a cryptic error message: $ git push error: unable to push to unqualified destination: HEAD The destination refspec neither matches an existing ref on the remote nor begins with refs/, and we are unable to guess a prefix based on the source ref. error: failed to push some refs to '[email protected]:artagnon/git' Fail early with a nicer error message: $ git push fatal: You are not currently on a branch. To push the history leading to the current (detached HEAD) state now, use git push ram HEAD:<name-of-remote-branch> Just like in the upstream and simple cases. Signed-off-by: Ramkumar Ramachandra <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 35ee69c commit 7b2ecd8

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

builtin/push.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ static void warn_unspecified_push_default_configuration(void)
175175

176176
static void setup_default_push_refspecs(struct remote *remote)
177177
{
178+
struct branch *branch;
179+
178180
switch (push_default) {
179181
default:
180182
case PUSH_DEFAULT_UNSPECIFIED:
@@ -194,6 +196,9 @@ static void setup_default_push_refspecs(struct remote *remote)
194196
break;
195197

196198
case PUSH_DEFAULT_CURRENT:
199+
branch = branch_get(NULL);
200+
if (!branch)
201+
die(_(message_detached_head_die), remote->name);
197202
add_refspec("HEAD");
198203
break;
199204

0 commit comments

Comments
 (0)