@@ -113,17 +113,19 @@ static NORETURN int die_push_simple(struct branch *branch, struct remote *remote
113
113
remote -> name , branch -> name , advice_maybe );
114
114
}
115
115
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
+
116
123
static void setup_push_upstream (struct remote * remote , int simple )
117
124
{
118
125
struct strbuf refspec = STRBUF_INIT ;
119
126
struct branch * branch = branch_get (NULL );
120
127
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 );
127
129
if (!branch -> merge_nr || !branch -> merge || !branch -> remote_name )
128
130
die (_ ("The current branch %s has no upstream branch.\n"
129
131
"To push the current branch and set the remote as upstream, use\n"
@@ -173,6 +175,8 @@ static void warn_unspecified_push_default_configuration(void)
173
175
174
176
static void setup_default_push_refspecs (struct remote * remote )
175
177
{
178
+ struct branch * branch ;
179
+
176
180
switch (push_default ) {
177
181
default :
178
182
case PUSH_DEFAULT_UNSPECIFIED :
@@ -192,7 +196,10 @@ static void setup_default_push_refspecs(struct remote *remote)
192
196
break ;
193
197
194
198
case PUSH_DEFAULT_CURRENT :
195
- add_refspec ("HEAD" );
199
+ branch = branch_get (NULL );
200
+ if (!branch )
201
+ die (_ (message_detached_head_die ), remote -> name );
202
+ add_refspec (branch -> name );
196
203
break ;
197
204
198
205
case PUSH_DEFAULT_NOTHING :
0 commit comments