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

[PATCH 04/10] push: add "git push HEAD" shorthand for 'push current branch to default repo'

From
Steffen Prohaska <prohaska@zib.de>
Date
Oct 28, 2007, 17:46 UTC
Message-ID
<11935935812185-git-send-email-prohaska@zib.de>
In-Reply-To
<1193593581486-git-send-email-prohaska@zib.de>

Sometimes it is handy to push only the current branch to the default remote repository. For example, if you created a branch using the '--track' option git knows that the current branch is linked to a specific remote. But up to now you needed to say "git push <defaultremote> <thisbranch>", which was quite annoying. You could have said "git push" but then _all_ branches would have been pushed to the default remote.

This commit introduces "git push HEAD", which resolves HEAD to the current branch and pushes only the current branch to its default remote.

Setups that have a remote named HEAD will break. But such a setup if unlikely to exist; and is not very sensible anyway.

Signed-off-by: Steffen Prohaska <prohaska@zib.de>
---
 Documentation/git-push.txt |    6 +++++-
 builtin-push.c             |    2 ++
 t/t5516-fetch-push.sh      |   12 ++++++++++++
 3 files changed, 19 insertions(+), 1 deletions(-)
diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt
index 67b354b..236898f 100644
--- a/Documentation/git-push.txt
+++ b/Documentation/git-push.txt
@@ -10,7 +10,7 @@ SYNOPSIS
 --------
 [verse]
 'git-push' [--all] [--dry-run] [--create] [--tags] [--receive-pack=<git-receive-pack>]
-           [--repo=all] [-f | --force] [-v] [<repository> <refspec>...]
+           [--repo=all] [-f | --force] [-v] [HEAD | <repository> <refspec>...]
 
 DESCRIPTION
 -----------
@@ -25,6 +25,10 @@ documentation for gitlink:git-receive-pack[1].
 
 OPTIONS
 -------
+HEAD::
+	Tells push to push the current branch to the default
+	remote repository.
+
 <repository>::
 	The "remote" repository that is destination of a push
 	operation.  See the section <<URLS,GIT URLS>> below.
diff --git a/builtin-push.c b/builtin-push.c
index 2e3c8c6..7c08e19 100644
--- a/builtin-push.c
+++ b/builtin-push.c
@@ -102,6 +102,8 @@ int cmd_push(int argc, const char **argv, const char *prefix)
 		const char *arg = argv[i];
 
 		if (arg[0] != '-') {
+			if (!strcmp("HEAD", arg))
+				break;
 			repo = arg;
 			i++;
 			break;
diff --git a/t/t5516-fetch-push.sh b/t/t5516-fetch-push.sh
index 8becaf8..2650e36 100755
--- a/t/t5516-fetch-push.sh
+++ b/t/t5516-fetch-push.sh
@@ -291,6 +291,18 @@ test_expect_success 'push with HEAD' '
 
 '
 
+test_expect_success 'push HEAD' '
+
+	mk_test heads/track &&
+	git remote add test testrepo &&
+	git fetch test &&
+	git checkout -b track test/track &&
+	git reset --hard master &&
+	git push HEAD &&
+	check_push_result $the_commit heads/track
+
+'
+
 test_expect_success 'push with HEAD (--create)' '
 
 	mk_test &&
-- 
1.5.3.4.439.ge8b49
Previous: Steffen ProhaskaNext: Steffen Prohaska
Message 5 of 53 in “improve refspec handling in push”
  1. 0/10 improve refspec handling in pushSteffen Prohaska, Oct 28, 2007
  2. 01/10 push: change push to fail if short refname does not existSteffen Prohaska, Oct 28, 2007
  3. 02/10 push: teach push new flag --createSteffen Prohaska, Oct 28, 2007
  4. 03/10 push: support pushing HEAD to real branch nameSteffen Prohaska, Oct 28, 2007
  5. 04/10 push: add "git push HEAD" shorthand for 'push current branch to default repo'Steffen Prohaska, Oct 28, 2007
  6. 05/10 rename ref_matches_abbrev() to ref_abbrev_matches_full_with_fetch_rules()Steffen Prohaska, Oct 28, 2007
  7. 06/10 add ref_abbrev_matches_full_with_rev_parse_rules() comparing abbrev with full ref nameSteffen Prohaska, Oct 28, 2007
  8. 07/10 push: use same rules as git-rev-parse to resolve refspecsSteffen Prohaska, Oct 28, 2007
  9. 08/10 push: teach push to accept --verbose optionSteffen Prohaska, Oct 28, 2007
  10. 09/10 push: teach push to pass --verbose option to transport layerSteffen Prohaska, Oct 28, 2007
  11. 10/10 push: teach push to be quiet if local ref is strict subset of remote refSteffen Prohaska, Oct 28, 2007
  12. Junio C HamanoOct 30, 2007
  13. Steffen ProhaskaOct 30, 2007
  14. Andreas EricssonOct 30, 2007
  15. Steffen ProhaskaOct 30, 2007
  16. Junio C HamanoOct 30, 2007
  17. Steffen ProhaskaOct 31, 2007
  18. Junio C HamanoOct 31, 2007
  19. Junio C HamanoOct 31, 2007
  20. Steffen ProhaskaOct 31, 2007
  21. Junio C HamanoOct 31, 2007
  22. Steffen ProhaskaOct 31, 2007
  23. Junio C HamanoOct 31, 2007
  24. Steffen ProhaskaNov 1, 2007
  25. Andreas EricssonNov 1, 2007
  26. Steffen ProhaskaNov 1, 2007
  27. Junio C HamanoNov 1, 2007
  28. Steffen ProhaskaNov 2, 2007
  29. Junio C HamanoNov 2, 2007
  30. Steffen ProhaskaNov 2, 2007
  31. Junio C HamanoNov 2, 2007
  32. Steffen ProhaskaNov 2, 2007
  33. Andreas EricssonNov 2, 2007
  34. Tom PrinceNov 2, 2007
  35. Andreas EricssonNov 2, 2007
  36. Steffen ProhaskaNov 2, 2007
  37. Junio C HamanoNov 2, 2007
  38. Junio C HamanoNov 2, 2007
  39. Andreas EricssonNov 1, 2007
  40. Steffen ProhaskaNov 1, 2007
  41. Andreas EricssonNov 1, 2007
  42. Wincent ColaiutaNov 2, 2007
  43. Johannes SchindelinNov 2, 2007
  44. Steffen ProhaskaNov 2, 2007
  45. Wincent ColaiutaNov 2, 2007
  46. Daniel BarkalowOct 30, 2007
  47. Junio C HamanoOct 30, 2007
  48. Steffen ProhaskaOct 30, 2007
  49. Junio C HamanoOct 30, 2007
  50. Junio C HamanoOct 30, 2007
  51. Junio C HamanoOct 30, 2007
  52. Steffen ProhaskaOct 30, 2007
  53. Junio C HamanoOct 30, 2007

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.