Skip to content

Commit bde7f73

Browse files
committed
Merge branch 'mm/push-default-advice'
* mm/push-default-advice: push: better error message when no remote configured push: better error messages when push.default = tracking
2 parents e2bbfed + a3f5e7a commit bde7f73

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

builtin/push.c

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,24 @@ static void set_refspecs(const char **refs, int nr)
6464
}
6565
}
6666

67-
static void setup_push_upstream(void)
67+
static void setup_push_upstream(struct remote *remote)
6868
{
6969
struct strbuf refspec = STRBUF_INIT;
7070
struct branch *branch = branch_get(NULL);
7171
if (!branch)
72-
die("You are not currently on a branch.");
72+
die("You are not currently on a branch.\n"
73+
"To push the history leading to the current (detached HEAD)\n"
74+
"state now, use\n"
75+
"\n"
76+
" git push %s HEAD:<name-of-remote-branch>\n",
77+
remote->name);
7378
if (!branch->merge_nr || !branch->merge)
74-
die("The current branch %s has no upstream branch.",
79+
die("The current branch %s has no upstream branch.\n"
80+
"To push the current branch and set the remote as upstream, use\n"
81+
"\n"
82+
" git push --set-upstream %s %s\n",
83+
branch->name,
84+
remote->name,
7585
branch->name);
7686
if (branch->merge_nr != 1)
7787
die("The current branch %s has multiple upstream branches, "
@@ -80,7 +90,7 @@ static void setup_push_upstream(void)
8090
add_refspec(refspec.buf);
8191
}
8292

83-
static void setup_default_push_refspecs(void)
93+
static void setup_default_push_refspecs(struct remote *remote)
8494
{
8595
switch (push_default) {
8696
default:
@@ -89,7 +99,7 @@ static void setup_default_push_refspecs(void)
8999
break;
90100

91101
case PUSH_DEFAULT_UPSTREAM:
92-
setup_push_upstream();
102+
setup_push_upstream(remote);
93103
break;
94104

95105
case PUSH_DEFAULT_CURRENT:
@@ -147,7 +157,14 @@ static int do_push(const char *repo, int flags)
147157
if (!remote) {
148158
if (repo)
149159
die("bad repository '%s'", repo);
150-
die("No destination configured to push to.");
160+
die("No configured push destination.\n"
161+
"Either specify the URL from the command-line or configure a remote repository using\n"
162+
"\n"
163+
" git remote add <name> <url>\n"
164+
"\n"
165+
"and then push using the remote name\n"
166+
"\n"
167+
" git push <name>\n");
151168
}
152169

153170
if (remote->mirror)
@@ -175,7 +192,7 @@ static int do_push(const char *repo, int flags)
175192
refspec = remote->push_refspec;
176193
refspec_nr = remote->push_refspec_nr;
177194
} else if (!(flags & TRANSPORT_PUSH_MIRROR))
178-
setup_default_push_refspecs();
195+
setup_default_push_refspecs(remote);
179196
}
180197
errs = 0;
181198
if (remote->pushurl_nr) {

0 commit comments

Comments
 (0)