threads / discuss / 30941

How do I delete a remote branch with a period in the name?

Subject: How do I delete a remote branch with a period in the name?

## tl;dr

17 messages between Jul 3, 2012 and Jul 5, 2012.

replies: 16people: 6as markdown or json

jonsmirl@gmail.com· Jul 3, 2012, 03:09 UTC · lore
How do I delete a remote branch with a period in the name?
jonsmirl@smirl2:/home/apps/florida/lpc31xx$ git push origin :fl
To git@github.com:jonsmirl/lpc31xx.git
 - [deleted]         fl

jonsmirl@smirl2:/home/apps/florida/lpc31xx$ git push origin :fl.stg error: unable to push to unqualified destination: fl.stg 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 'git@github.com:jonsmirl/lpc31xx.git' jonsmirl@smirl2:/home/apps/florida/lpc31xx$

jonsmirl@smirl2:/home/apps/florida/lpc31xx$ git branch -r
  linus/master
  origin/HEAD -> origin/master
  origin/bar.stgit
  origin/dt-test
  origin/fl.stgit
  origin/foo.stgit
  origin/lpc313x-stg
  origin/lpc313x-stg.stgit
  origin/master
  origin/master.stgit
  origin/temp.stgit
  origin/v3.4-stg
  origin/v3.4-stg.stgit
  origin/v3.5-stg
  origin/v3.5-stg.stgit

-- Jon Smirl jonsmirl@gmail.com

Junio C Hamano· Jul 3, 2012, 04:14 UTC · re: jonsmirl@gmail.com · lore

Re: How do I delete a remote branch with a period in the name?

"jonsmirl@gmail.com" <jonsmirl@gmail.com> writes:
> jonsmirl@smirl2:/home/apps/florida/lpc31xx$ git push origin :fl.stg
> error: unable to push to unqualified destination: fl.stg
> 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.

The message seems to be saying that fl.stg is not specific enough perhaps? What does "git ls-remote origin | grep fl.stg" say? If it says refs/smirl/fl.stg, for example, you can be specific as the message suggests, e.g. "git push origin :refs/smirl/fl.stg" or something like that?

jonsmirl@gmail.com· Jul 3, 2012, 11:42 UTC · re: Junio C Hamano · lore

Re: How do I delete a remote branch with a period in the name?

On Tue, Jul 3, 2012 at 12:14 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 12 quoted lines
> "jonsmirl@gmail.com" <jonsmirl@gmail.com> writes:
>
>> jonsmirl@smirl2:/home/apps/florida/lpc31xx$ git push origin :fl.stg
>> error: unable to push to unqualified destination: fl.stg
>> 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.
>
> The message seems to be saying that fl.stg is not specific enough
> perhaps?  What does "git ls-remote origin | grep fl.stg" say?  If it
> says refs/smirl/fl.stg, for example, you can be specific as the
> message suggests, e.g. "git push origin :refs/smirl/fl.stg" or
> something like that?

I have the branch name wrong. It is fl.stgit not fl.stg. But the error message sent me off in the wrong direction looking for an answer.

-- 
Jon Smirl
jonsmirl@gmail.com
Jeff King· Jul 3, 2012, 18:04 UTC · re: jonsmirl@gmail.com · lore

[PATCH] push: don't guess at qualifying remote refs on deletion

When we try to push a ref and the right-hand side of the refspec does not find a match, we try to create it. If it is not fully qualified, we try to guess where it would go in the refs hierarchy based on the left-hand source side. If the source side is not a ref, then we give up and give a long explanatory message.

For deletions, however, this doesn't make any sense. We would never want to create on the remote side, and if an unqualified ref can't be matched, it is simply an error. The current code handles this already because the left-hand side is empty, and therefore does not give us a hint as to where the right-hand side should go, and we properly error out. Unfortunately, the error message is the long "we tried to qualify this, but the source side didn't let us guess" message, which is quite confusing.

Instead, we can just be more succinct and say "we can't delete this because we couldn't find it". So before:

  $ git push origin :bogus
  error: unable to push to unqualified destination: bogus
  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 '$URL'
and now:
  $ git push origin :bogus
  error: unable to delete 'bogus': remote ref does not exist
  error: failed to push some refs to '$URL'

It is tempting to also catch a fully-qualified ref like "refs/heads/bogus" and generate the same error message. However, that currently does not error out at all, and instead gets sent to the remote side, which typically generates a warning:

  $ git push origin:refs/heads/bogus
  remote: warning: Deleting a non-existent ref.
  To $URL
   - [deleted]         bogus

While it would be nice to catch this error early, a client-side error would mean aborting the push entirely and changing push's exit code. For example, right now you can do:

  $ git push origin refs/heads/foo refs/heads/bar

and end up in a state where "foo" and "bar" are deleted, whether both of them currently exist or not (and see an error only if we actually failed to contact the server). Generating an error would cause a regression for this use case.

Signed-off-by: Jeff King <peff@peff.net>
---
On Tue, Jul 03, 2012 at 07:42:07AM -0400, jonsmirl@gmail.com wrote:
> I have the branch name wrong. It is fl.stgit not fl.stg.
> But the error message sent me off in the wrong direction looking for an answer.

I think this would help. I used "remote ref does not exist" because that is the simplest explanation for the user. However, given that we will try to push a fully qualified ref that does not exist, a more accurate message might "destination refspec did not match" or something similar. I prefer the former, though, as it less arcane.

 remote.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/remote.c b/remote.c
index 6833538..04fd9ea 100644
--- a/remote.c
+++ b/remote.c
@@ -1100,6 +1100,9 @@ static int match_explicit(struct ref *src, struct ref *dst,
 	case 0:
 		if (!memcmp(dst_value, "refs/", 5))
 			matched_dst = make_linked_ref(dst_value, dst_tail);
+		else if (is_null_sha1(matched_src->new_sha1))
+			error("unable to delete '%s': remote ref does not exist",
+			      dst_value);
 		else if ((dst_guess = guess_ref(dst_value, matched_src)))
 			matched_dst = make_linked_ref(dst_guess, dst_tail);
 		else
-- 
1.7.11.rc1.21.g3c8d91e
jonsmirl@gmail.com· Jul 3, 2012, 18:34 UTC · re: Jeff King · lore

Re: [PATCH] push: don't guess at qualifying remote refs on deletion

On Tue, Jul 3, 2012 at 2:04 PM, Jeff King <peff@peff.net> wrote:
Show 31 quoted lines
> When we try to push a ref and the right-hand side of the
> refspec does not find a match, we try to create it. If it is
> not fully qualified, we try to guess where it would go in
> the refs hierarchy based on the left-hand source side. If
> the source side is not a ref, then we give up and give a
> long explanatory message.
>
> For deletions, however, this doesn't make any sense. We
> would never want to create on the remote side, and if an
> unqualified ref can't be matched, it is simply an error. The
> current code handles this already because the left-hand side
> is empty, and therefore does not give us a hint as to where
> the right-hand side should go, and we properly error out.
> Unfortunately, the error message is the long "we tried to
> qualify this, but the source side didn't let us guess"
> message, which is quite confusing.
>
> Instead, we can just be more succinct and say "we can't
> delete this because we couldn't find it". So before:
>
>   $ git push origin :bogus
>   error: unable to push to unqualified destination: bogus
>   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 '$URL'
>
> and now:
>
>   $ git push origin :bogus
>   error: unable to delete 'bogus': remote ref does not exist
>   error: failed to push some refs to '$URL'
This error return would have made my mistake obvious.

Might want to add a paragraph to the doc saying this is how you delete remote branches since it is not an obvious solution. I found it via Google and a question asked on stackoverflow.com

Show 58 quoted lines
> It is tempting to also catch a fully-qualified ref like
> "refs/heads/bogus" and generate the same error message.
> However, that currently does not error out at all, and
> instead gets sent to the remote side, which typically
> generates a warning:
>
>   $ git push origin:refs/heads/bogus
>   remote: warning: Deleting a non-existent ref.
>   To $URL
>    - [deleted]         bogus
>
> While it would be nice to catch this error early, a
> client-side error would mean aborting the push entirely and
> changing push's exit code. For example, right now you can
> do:
>
>   $ git push origin refs/heads/foo refs/heads/bar
>
> and end up in a state where "foo" and "bar" are deleted,
> whether both of them currently exist or not (and see an
> error only if we actually failed to contact the server).
> Generating an error would cause a regression for this use
> case.
>
> Signed-off-by: Jeff King <peff@peff.net>
> ---
> On Tue, Jul 03, 2012 at 07:42:07AM -0400, jonsmirl@gmail.com wrote:
>
>> I have the branch name wrong. It is fl.stgit not fl.stg.
>> But the error message sent me off in the wrong direction looking for an answer.
>
> I think this would help. I used "remote ref does not exist"
> because that is the simplest explanation for the user.
> However, given that we will try to push a fully qualified
> ref that does not exist, a more accurate message might
> "destination refspec did not match" or something similar.  I
> prefer the former, though, as it less arcane.
>
>  remote.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/remote.c b/remote.c
> index 6833538..04fd9ea 100644
> --- a/remote.c
> +++ b/remote.c
> @@ -1100,6 +1100,9 @@ static int match_explicit(struct ref *src, struct ref *dst,
>         case 0:
>                 if (!memcmp(dst_value, "refs/", 5))
>                         matched_dst = make_linked_ref(dst_value, dst_tail);
> +               else if (is_null_sha1(matched_src->new_sha1))
> +                       error("unable to delete '%s': remote ref does not exist",
> +                             dst_value);
>                 else if ((dst_guess = guess_ref(dst_value, matched_src)))
>                         matched_dst = make_linked_ref(dst_guess, dst_tail);
>                 else
> --
> 1.7.11.rc1.21.g3c8d91e
>
-- 
Jon Smirl
jonsmirl@gmail.com
Jeff King· Jul 3, 2012, 18:40 UTC · re: jonsmirl@gmail.com · lore

Re: [PATCH] push: don't guess at qualifying remote refs on deletion

On Tue, Jul 03, 2012 at 02:34:59PM -0400, jonsmirl@gmail.com wrote:
Show 7 quoted lines
> > and now:
> >
> >   $ git push origin :bogus
> >   error: unable to delete 'bogus': remote ref does not exist
> >   error: failed to push some refs to '$URL'
> 
> This error return would have made my mistake obvious.
Thanks for confirming.
> Might want to add a paragraph to the doc saying this is how you delete
> remote branches since it is not an obvious solution. I found it via
> Google and a question asked on stackoverflow.com
It's already in git-push(1):
  OPTIONS
     ...
     <refspec>
       ...
       Pushing an empty <src> allows you to delete the <dst> ref from
       the remote repository.

but if you have rewording suggestions, or a suggestion as to where else to mention it, please do.

-Peff
jonsmirl@gmail.com· Jul 3, 2012, 18:43 UTC · re: Jeff King · lore

Re: [PATCH] push: don't guess at qualifying remote refs on deletion

On Tue, Jul 3, 2012 at 2:40 PM, Jeff King <peff@peff.net> wrote:
Show 23 quoted lines
> On Tue, Jul 03, 2012 at 02:34:59PM -0400, jonsmirl@gmail.com wrote:
>
>> > and now:
>> >
>> >   $ git push origin :bogus
>> >   error: unable to delete 'bogus': remote ref does not exist
>> >   error: failed to push some refs to '$URL'
>>
>> This error return would have made my mistake obvious.
>
> Thanks for confirming.
>
>> Might want to add a paragraph to the doc saying this is how you delete
>> remote branches since it is not an obvious solution. I found it via
>> Google and a question asked on stackoverflow.com
>
> It's already in git-push(1):
>
>   OPTIONS
>      ...
>      <refspec>
>        ...
>        Pushing an empty <src> allows you to delete the <dst> ref from

I was searching for "git delete remote branch". Can out add the word 'branch' in so that Google will find it?

Show 6 quoted lines
>        the remote repository.
>
> but if you have rewording suggestions, or a suggestion as to where else
> to mention it, please do.
>
> -Peff
-- 
Jon Smirl
jonsmirl@gmail.com
Jeff King· Jul 3, 2012, 19:35 UTC · re: jonsmirl@gmail.com · lore

Re: [PATCH] push: don't guess at qualifying remote refs on deletion

On Tue, Jul 03, 2012 at 02:43:01PM -0400, jonsmirl@gmail.com wrote:
Show 10 quoted lines
> > It's already in git-push(1):
> >
> >   OPTIONS
> >      ...
> >      <refspec>
> >        ...
> >        Pushing an empty <src> allows you to delete the <dst> ref from
> 
> I was searching for "git delete remote branch". Can out add the word
> 'branch' in so that Google will find it?
I didn't quite parse what you were saying here.
-Peff
Carlos Martín Nieto· Jul 4, 2012, 07:21 UTC · re: Jeff King · lore

Re: [PATCH] push: don't guess at qualifying remote refs on deletion

On Tue, 2012-07-03 at 14:40 -0400, Jeff King wrote:
Show 25 quoted lines
> On Tue, Jul 03, 2012 at 02:34:59PM -0400, jonsmirl@gmail.com wrote:
> 
> > > and now:
> > >
> > >   $ git push origin :bogus
> > >   error: unable to delete 'bogus': remote ref does not exist
> > >   error: failed to push some refs to '$URL'
> > 
> > This error return would have made my mistake obvious.
> 
> Thanks for confirming.
> 
> > Might want to add a paragraph to the doc saying this is how you delete
> > remote branches since it is not an obvious solution. I found it via
> > Google and a question asked on stackoverflow.com
> 
> It's already in git-push(1):
> 
>   OPTIONS
>      ...
>      <refspec>
>        ...
>        Pushing an empty <src> allows you to delete the <dst> ref from
>        the remote repository.
> 

There is also a flag you can pass, which you can see a few paragraphs under it which. It explains what it does underneath but removes the need to know that an empty source will delete the ref.

    --delete
       All listed refs are deleted from the remote repository. This is
       the same as prefixing all refs with a colon.

I suppose "delete" rather than "remove" as we have for remotes could cause some confusion, as it's inconsistent, but it's all there in the manpage.

   cmn
Junio C Hamano· Jul 3, 2012, 19:38 UTC · re: Jeff King · lore

Re: [PATCH] push: don't guess at qualifying remote refs on deletion

Jeff King <peff@peff.net> writes:
Show 14 quoted lines
> Instead, we can just be more succinct and say "we can't
> delete this because we couldn't find it". So before:
>
>   $ git push origin :bogus
>   error: unable to push to unqualified destination: bogus
>   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 '$URL'
>
> and now:
>
>   $ git push origin :bogus
>   error: unable to delete 'bogus': remote ref does not exist
>   error: failed to push some refs to '$URL'

This is telling a truth ($GIT_DIR/refs/bogus does not exist) but not the whole truth; while I tend to agree that it is better than the original (especially with ", and we are unable to guess..." part), given that the above request would delete refs/tags/bogus or refs/heads/bogus if they existed on the "origin", I am a bit worried that it may send an incorrect message to novice users.

    unable to delete 'bogus': no branch or tag with that name

might allay my worries, but I am not extremely happy with that wording, either.

Show 6 quoted lines
> I think this would help. I used "remote ref does not exist"
> because that is the simplest explanation for the user.
> However, given that we will try to push a fully qualified
> ref that does not exist, a more accurate message might
> "destination refspec did not match" or something similar.  I
> prefer the former, though, as it less arcane.
Yeah, I do understand why you phrased that way, but still..
Jeff King· Jul 4, 2012, 07:37 UTC · re: Junio C Hamano · lore

Re: [PATCH] push: don't guess at qualifying remote refs on deletion

On Tue, Jul 03, 2012 at 12:38:10PM -0700, Junio C Hamano wrote:
Show 28 quoted lines
> Jeff King <peff@peff.net> writes:
> 
> > Instead, we can just be more succinct and say "we can't
> > delete this because we couldn't find it". So before:
> >
> >   $ git push origin :bogus
> >   error: unable to push to unqualified destination: bogus
> >   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 '$URL'
> >
> > and now:
> >
> >   $ git push origin :bogus
> >   error: unable to delete 'bogus': remote ref does not exist
> >   error: failed to push some refs to '$URL'
> 
> This is telling a truth ($GIT_DIR/refs/bogus does not exist) but not
> the whole truth; while I tend to agree that it is better than the
> original (especially with ", and we are unable to guess..." part),
> given that the above request would delete refs/tags/bogus or
> refs/heads/bogus if they existed on the "origin", I am a bit worried
> that it may send an incorrect message to novice users.
> 
>     unable to delete 'bogus': no branch or tag with that name
> 
> might allay my worries, but I am not extremely happy with that
> wording, either.

I think the most accurate explanation of the behavior is "the destination refspec does not match an existing ref, and it is not fully qualified, so I didn't know what you meant to delete". But that is a pretty awful message (only slightly less awful than the original one, but I think that one is pretty bad).

The really interesting part is that we tried to match "bogus" against all of the usual ref lookup rules, and it didn't match anything. But we have the same issue when we say "git show bogus" and it does not match anything, and we simply say "bad revision 'bogus'".

Maybe:
  unable to delete 'bogus': no matching remote ref found
would be a reasonably short way of saying that?

That still leaves out the second half, that it was not fully qualified and therefore we could not even transmit an attempt to delete (even though that attempt would clearly not succeed!). But that is really not a subtlety that I think is worth putting in the error message, as it is way more likely to confuse somebody.

-Peff
Andreas Schwab· Jul 3, 2012, 07:56 UTC · re: jonsmirl@gmail.com · lore

Re: How do I delete a remote branch with a period in the name?

"jonsmirl@gmail.com" <jonsmirl@gmail.com> writes:
Show 23 quoted lines
> jonsmirl@smirl2:/home/apps/florida/lpc31xx$ git push origin :fl.stg
> error: unable to push to unqualified destination: fl.stg
> 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 'git@github.com:jonsmirl/lpc31xx.git'
> jonsmirl@smirl2:/home/apps/florida/lpc31xx$
>
> jonsmirl@smirl2:/home/apps/florida/lpc31xx$ git branch -r
>   linus/master
>   origin/HEAD -> origin/master
>   origin/bar.stgit
>   origin/dt-test
>   origin/fl.stgit
>   origin/foo.stgit
>   origin/lpc313x-stg
>   origin/lpc313x-stg.stgit
>   origin/master
>   origin/master.stgit
>   origin/temp.stgit
>   origin/v3.4-stg
>   origin/v3.4-stg.stgit
>   origin/v3.5-stg
>   origin/v3.5-stg.stgit
There doesn't appear to be a remote branch with that name.
Andreas.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Junio C Hamano· Jul 3, 2012, 19:39 UTC · re: Andreas Schwab · lore

Re: How do I delete a remote branch with a period in the name?

Andreas Schwab <schwab@linux-m68k.org> writes:
Show 27 quoted lines
> "jonsmirl@gmail.com" <jonsmirl@gmail.com> writes:
>
>> jonsmirl@smirl2:/home/apps/florida/lpc31xx$ git push origin :fl.stg
>> error: unable to push to unqualified destination: fl.stg
>> 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 'git@github.com:jonsmirl/lpc31xx.git'
>> jonsmirl@smirl2:/home/apps/florida/lpc31xx$
>>
>> jonsmirl@smirl2:/home/apps/florida/lpc31xx$ git branch -r
>>   linus/master
>>   origin/HEAD -> origin/master
>>   origin/bar.stgit
>>   origin/dt-test
>>   origin/fl.stgit
>>   origin/foo.stgit
>>   origin/lpc313x-stg
>>   origin/lpc313x-stg.stgit
>>   origin/master
>>   origin/master.stgit
>>   origin/temp.stgit
>>   origin/v3.4-stg
>>   origin/v3.4-stg.stgit
>>   origin/v3.5-stg
>>   origin/v3.5-stg.stgit
>
> There doesn't appear to be a remote branch with that name.

More importantly, there was nothing in Jon's message to convince us that "branch -r" outputis telling us the current state of the remote. Showing "ls-remote" output would have been better.

Carlos Martín Nieto· Jul 5, 2012, 07:22 UTC · lore

Re: [PATCH] push: don't guess at qualifying remote refs on deletion

On Wed, 2012-07-04 at 22:23 -0400, Phil Hord wrote:
Show 48 quoted lines
> 
> On Jul 4, 2012 3:22 AM, "Carlos Martín Nieto" <cmn@elego.de> wrote:
> >
> > On Tue, 2012-07-03 at 14:40 -0400, Jeff King wrote:
> > > On Tue, Jul 03, 2012 at 02:34:59PM -0400, jonsmirl@gmail.com
> wrote:
> > >
> > > > > and now:
> > > > >
> > > > >   $ git push origin :bogus
> > > > >   error: unable to delete 'bogus': remote ref does not exist
> > > > >   error: failed to push some refs to '$URL'
> > > >
> > > > This error return would have made my mistake obvious.
> > >
> > > Thanks for confirming.
> > >
> > > > Might want to add a paragraph to the doc saying this is how you
> delete
> > > > remote branches since it is not an obvious solution. I found it
> via
> > > > Google and a question asked on stackoverflow.com
> > >
> > > It's already in git-push(1):
> > >
> > >   OPTIONS
> > >      ...
> > >      <refspec>
> > >        ...
> > >        Pushing an empty <src> allows you to delete the <dst> ref
> from
> > >        the remote repository.
> > >
> >
> > There is also a flag you can pass, which you can see a few
> paragraphs
> > under it which. It explains what it does underneath but removes the
> need
> > to know that an empty source will delete the ref.
> >
> >     --delete
> >        All listed refs are deleted from the remote repository. This
> is
> >        the same as prefixing all refs with a colon.
> 
> 
> I do like that, but I agree with OP that 'git push' is not an obvious
> to look for delete branch functionality for new users.

Like it? I don't get what you mean, it's a quote of what's already there.

The reason that it's in git-push is because that's the only git command that modifies another repository. There isn't another git command where it would fit. You could try to put it somewhere under git-remote, but then you'd have a single subcommand that affects a remote among a lot of others that don't, introducing an inconsistency in the command.

   cmn
Phil Hord· Jul 5, 2012, 15:32 UTC · re: Carlos Martín Nieto · lore

Re: [PATCH] push: don't guess at qualifying remote refs on deletion

Show 14 quoted lines
>> > There is also a flag you can pass, which you can see a few
>> paragraphs
>> > under it which. It explains what it does underneath but removes the
>> need
>> > to know that an empty source will delete the ref.
>> >
>> >     --delete
>> >        All listed refs are deleted from the remote repository. This
>> is
>> >        the same as prefixing all refs with a colon.
>>
>>
>> I do like that, but I agree with OP that 'git push' is not an obvious
>> to look for delete branch functionality for new users.
s/obvious/obvious place/
> Like it? I don't get what you mean, it's a quote of what's already
> there.

Yes. I didn't mean I like "the change". I meant that I appreciate this being in the documentation. But it seems insufficient.

> The reason that it's in git-push is because that's the only git command
> that modifies another repository. There isn't another git command where
> it would fit.
Yes, and that's why I said, in the part of my email you did not quote:
"I do not have a good suggestion for improving the situation, however."
> You could try to put it somewhere under git-remote, but
> then you'd have a single subcommand that affects a remote among a lot of
> others that don't, introducing an inconsistency in the command.

git-remote is the wrong place for anything like this. I think git-push is really the correct place for it. I do not think it should be moved.

But this is a common problem in git for newbies, I think. Features are in "the right place" in the command structure, but it is difficult to find where that right place is when you are new to the system, especially when the feature is tucked neatly away as a switch on some other feature.

The possible enhancements to cover this I can think of are mostly in the form of enhanced help or advice. For example, I could imagine these:

1. Add a link to 'git push' on the 'git-branch' man page.   I suspect
this is where newbies would go to look for this feature, but I am only
guessing.  The git-branch help discusses deleting branches and even
deleting remote-tracking branches.  But it does not discuss deleting
branches on a remote repository, even to say "this is not the command
you want" for that action, but "see this other one instead".
2. Add 'apropos' behavior for git help.
   $ git apropos delete
Except I notice that the system 'apropos' does not turn up 'git-push'
for either of these:
   $ apropos delete
   $ apropos branch
3. Add a search feature for help.  Currently this feature is provided
instead by Google and StackOverflow.
   $ git help --find delete --and branch --and remote
Except I don't expect this "advanced" form of help, if it existed, to
be noticed by newbies early enough on the learning curve.
4. Add advice in appropriate locations.
Instead of this:
   $ git remote rm origin/foo
   error: Could not remove config section 'remote.origin/foo'
   $ git branch -d origin/foo
   error: branch 'origin/foo' not found.
Do this:
   $ git remote rm origin/foo
   error: There is no remote named 'origin/foo'
   hint: Did you mean to remove the remote tracking branch 'origin/foo'?
   hint: Try "git branch --delete --remotes origin/foo" instead.
   hint: Did you mean to remove the branch 'foo' on the remote
'origin' repository?
   hint: Try "git push --delete origin foo" instead.
   $ git branch -d origin/foo
   error: branch 'origin/foo' not found.
   hint: To delete the remote-tracking branch origin/foo,
   hint:  use git branch --delete --remotes origin/foo
   $ git branch -dr origin/foo
   Deleted remote branch origin/foo (was fadda12).
   hint: This deleted your remote-tracking branch but
   hint:  did not affect the branch on the remote server.
   hint:  To remove the branch from the remote server,
   hint:  use "git push".  See '--delete' in "git help push" .
I rather like this last bit.  I'll try to roll a patch later on.
Phil
Carlos Martín Nieto· Jul 5, 2012, 17:24 UTC · re: Phil Hord · lore

Re: [PATCH] push: don't guess at qualifying remote refs on deletion

On Thu, 2012-07-05 at 11:32 -0400, Phil Hord wrote:
Show 11 quoted lines
> 
> The possible enhancements to cover this I can think of are mostly in
> the form of enhanced help or advice.  For example, I could imagine
> these:
> 
> 1. Add a link to 'git push' on the 'git-branch' man page.   I suspect
> this is where newbies would go to look for this feature, but I am only
> guessing.  The git-branch help discusses deleting branches and even
> deleting remote-tracking branches.  But it does not discuss deleting
> branches on a remote repository, even to say "this is not the command
> you want" for that action, but "see this other one instead".
Yeah, that seems like a good addition.
Show 8 quoted lines
> 
> 2. Add 'apropos' behavior for git help.
>    $ git apropos delete
> 
> Except I notice that the system 'apropos' does not turn up 'git-push'
> for either of these:
>    $ apropos delete
>    $ apropos branch

Huh, I don't think I've used apropos in years. I guess changing the subject to include removing/deleting would be conceivable, but we still have the issue that branches are a particular form of ref, which is what push acts on.

Show 11 quoted lines
> 
> 3. Add a search feature for help.  Currently this feature is provided
> instead by Google and StackOverflow.
>    $ git help --find delete --and branch --and remote
> Except I don't expect this "advanced" form of help, if it existed, to
> be noticed by newbies early enough on the learning curve.
> 
> 4. Add advice in appropriate locations.
> Instead of this:
>    $ git remote rm origin/foo
>    error: Could not remove config section 'remote.origin/foo'

Ugh, this is horrible. We should definitely do better than this error message.

Show 19 quoted lines
>    $ git branch -d origin/foo
>    error: branch 'origin/foo' not found.
> 
> Do this:
>    $ git remote rm origin/foo
>    error: There is no remote named 'origin/foo'
>    hint: Did you mean to remove the remote tracking branch 'origin/foo'?
>    hint: Try "git branch --delete --remotes origin/foo" instead.
>    hint: Did you mean to remove the branch 'foo' on the remote
> 'origin' repository?
>    hint: Try "git push --delete origin foo" instead.
> 
>    $ git branch -d origin/foo
>    error: branch 'origin/foo' not found.
>    hint: To delete the remote-tracking branch origin/foo,
>    hint:  use git branch --delete --remotes origin/foo
> 
>    $ git branch -dr origin/foo
>    Deleted remote branch origin/foo (was fadda12).

If we're changing error messages, this could probably do with an update to say "remote-tracking" branch so it's clearer that it didn't affect the branch on the remote.

Show 5 quoted lines
>    hint: This deleted your remote-tracking branch but
>    hint:  did not affect the branch on the remote server.
>    hint:  To remove the branch from the remote server,
>    hint:  use "git push".  See '--delete' in "git help push" .
> 

IMO these seem too verbose (but maybe I've just seen people post the old 'git pull' error message without even reading it too many times).

   cmn
Junio C Hamano· Jul 5, 2012, 17:26 UTC · re: Phil Hord · lore

Re: [PATCH] push: don't guess at qualifying remote refs on deletion

Phil Hord <phil.hord@gmail.com> writes:
> The possible enhancements to cover this I can think of are mostly in
> the form of enhanced help or advice.  For example, I could imagine
> these:
Thanks; I agree discoverability is the key for any large toolset.
Show 6 quoted lines
> 1. Add a link to 'git push' on the 'git-branch' man page.   I suspect
> this is where newbies would go to look for this feature, but I am only
> guessing.  The git-branch help discusses deleting branches and even
> deleting remote-tracking branches.  But it does not discuss deleting
> branches on a remote repository, even to say "this is not the command
> you want" for that action, but "see this other one instead".

Or you can enhance the link to "git push" from "git" manpage (which hopefully exists already), to make it clear that everything that affects branches and tags that appear at a remote site is done via that command.

Show 8 quoted lines
> 2. Add 'apropos' behavior for git help.
>    $ git apropos delete
> ...
> 3. Add a search feature for help.  Currently this feature is provided
> instead by Google and StackOverflow.
>    $ git help --find delete --and branch --and remote
> Except I don't expect this "advanced" form of help, if it existed, to
> be noticed by newbies early enough on the learning curve.

I think you may be onto something here. I can see that we could help "git help -k delete" (modeled after "man -k") by adding keywords to the documentation pages.

> 4. Add advice in appropriate locations.

I have to say that I am fairly negative on any attempt to anticipate and list all the irrelevant possibilities that could come from misunderstandings; it will lead to unreadable mess.

← back to recent threads