git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH 1/2] add a --delete option to git push

From
Sverre Rabbelier <srabbelier@gmail.com>
Date
Aug 14, 2009, 05:05 UTC
Message-ID
<1250226349-20397-2-git-send-email-srabbelier@gmail.com>
In-Reply-To
<1250226349-20397-1-git-send-email-srabbelier@gmail.com>

Those new to git have a hard time learning how to delete a remote ref. This makes it easier for them to find out how by providing a flag to git push.

Signed-off-by: Sverre Rabbelier <srabbelier@gmail.com>
---
    Currently `git push --delete master:master` results in a somewhat
    cryptic error message. It seems unlikely however, that those new
    to git would use the 'old:new' notation, so I haven't bothered
    guarding against it and settled for documenting it.
 Documentation/git-push.txt |    8 +++++++-
 builtin-push.c             |   10 +++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt
index 58d2bd5..1ecc6ca 100644
--- a/Documentation/git-push.txt
+++ b/Documentation/git-push.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git push' [--all | --mirror | --tags] [--dry-run] [--receive-pack=<git-receive-pack>]
-	   [--repo=<repository>] [-f | --force] [-v | --verbose]
+	   [--repo=<repository>] [-f | --force] [-v | --verbose] [-d | --delete]
 	   [<repository> <refspec>...]
 
 DESCRIPTION
@@ -137,6 +137,12 @@ useful if you write an alias or script around 'git-push'.
 --verbose::
 	Run verbosely.
 
+-d::
+--delete::
+    Delete the specified refs. Prefixes all refs with ':' to tell the
+    push machinery to delete the specified ref. As such, the refs
+    that are to be deleted should not contain a ':' specifier.
+
 include::urls-remotes.txt[]
 
 OUTPUT
diff --git a/builtin-push.c b/builtin-push.c
index 67f6d96..b954235 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -10,11 +10,12 @@
 #include "parse-options.h"
 
 static const char * const push_usage[] = {
-	"git push [--all | --mirror] [--dry-run] [--porcelain] [--tags] [--receive-pack=<git-receive-pack>] [--repo=<repository>] [-f | --force] [-v] [<repository> <refspec>...]",
+	"git push [--all | --mirror] [--dry-run] [--porcelain] [--tags] [--receive-pack=<git-receive-pack>] [--repo=<repository>] [-f | --force] [-v] [-d | --delete] [<repository> <refspec>...]",
 	NULL,
 };
 
 static int thin;
+static int push_delete;
 static const char *receivepack;
 
 static const char **refspec;
@@ -44,6 +45,12 @@ static void set_refspecs(const char **refs, int nr)
 			strcat(tag, refs[i]);
 			ref = tag;
 		}
+		if (push_delete) {
+			struct strbuf deleted = STRBUF_INIT;
+			strbuf_addstr(&deleted, ":");
+			strbuf_addstr(&deleted, refs[i]);
+			ref = strbuf_detach(&deleted, NULL);
+		}
 		add_refspec(ref);
 	}
 }
@@ -188,6 +195,7 @@ int cmd_push(int argc, const char **argv, const char *prefix)
 		OPT_BOOLEAN( 0 , "thin", &thin, "use thin pack"),
 		OPT_STRING( 0 , "receive-pack", &receivepack, "receive-pack", "receive pack program"),
 		OPT_STRING( 0 , "exec", &receivepack, "receive-pack", "receive pack program"),
+		OPT_BOOLEAN('d', "delete", &push_delete, "delete ref"),
 		OPT_END()
 	};
 
-- 
1.6.4.16.g72c66.dirty
Previous: Sverre RabbelierNext: Sverre Rabbelier
Message 2 of 18 in “add a --delete option to git push”
  1. 0/2 add a --delete option to git pushSverre Rabbelier, Aug 14, 2009
  2. 1/2 add a --delete option to git pushSverre Rabbelier, Aug 14, 2009
  3. 2/2 test that git push --delete deletes the remote refSverre Rabbelier, Aug 14, 2009
  4. Jeff KingAug 14, 2009
  5. Sverre RabbelierAug 14, 2009
  6. Jeff KingAug 14, 2009
  7. Sverre RabbelierAug 14, 2009
  8. Jeff KingAug 14, 2009
  9. Junio C HamanoAug 14, 2009
  10. Jeff KingAug 14, 2009
  11. Jeff KingAug 14, 2009
  12. Sverre RabbelierAug 14, 2009
  13. Junio C HamanoAug 14, 2009
  14. Junio C HamanoAug 15, 2009
  15. Sverre RabbelierAug 16, 2009
  16. Jakub NarebskiAug 16, 2009
  17. Jakub NarebskiAug 14, 2009
  18. Jakub NarebskiAug 14, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.