Skip to content

Commit 35ee69c

Browse files
artagnongitster
authored andcommitted
push: factor out the detached HEAD error message
With push.default set to upstream or simple, and a detached HEAD, git push prints the following error: $ 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> This error is not unique to upstream or simple: current cannot push with a detached HEAD either. So, factor out the error string in preparation for using it in current. Signed-off-by: Ramkumar Ramachandra <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent edca415 commit 35ee69c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

builtin/push.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,19 @@ static NORETURN int die_push_simple(struct branch *branch, struct remote *remote
113113
remote->name, branch->name, advice_maybe);
114114
}
115115

116+
static const char message_detached_head_die[] =
117+
N_("You are not currently on a branch.\n"
118+
"To push the history leading to the current (detached HEAD)\n"
119+
"state now, use\n"
120+
"\n"
121+
" git push %s HEAD:<name-of-remote-branch>\n");
122+
116123
static void setup_push_upstream(struct remote *remote, int simple)
117124
{
118125
struct strbuf refspec = STRBUF_INIT;
119126
struct branch *branch = branch_get(NULL);
120127
if (!branch)
121-
die(_("You are not currently on a branch.\n"
122-
"To push the history leading to the current (detached HEAD)\n"
123-
"state now, use\n"
124-
"\n"
125-
" git push %s HEAD:<name-of-remote-branch>\n"),
126-
remote->name);
128+
die(_(message_detached_head_die), remote->name);
127129
if (!branch->merge_nr || !branch->merge || !branch->remote_name)
128130
die(_("The current branch %s has no upstream branch.\n"
129131
"To push the current branch and set the remote as upstream, use\n"

0 commit comments

Comments
 (0)