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

Re: [PATCH] git builtin "push"

From
Junio C Hamano <junkio@cox.net>
Date
Apr 30, 2006, 21:47 UTC
Message-ID
<7vslnuybuj.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<Pine.LNX.4.64.0604301405070.2922@g5.osdl.org>
Linus Torvalds <torvalds@osdl.org> writes:
Show 8 quoted lines
>> True, as long as you don't have any Push: lines in your .git/remotes/repo
>> file.  Any such lines act just like you gave them on the command line
>> which afaik effectively removes the ability to say "update all branches
>> we have in common".
>
> Ok, so my built-in version "fixes" that "feature". 
>
> 		Linus

Alternatively/additionally you could do something like the attached patch. However,...

I suspect that destination repositories that you would want to define Push: and the ones you do not want to have any Push: are of different nature and you would not mix them. When you do want to have any Push: line for a repository, you would _never_ want to use the "matching refs" semantics for that repository. So in that sense, the "fix" is not necessary, and fixing it would probably lead to more confusion.

The Push: lines can do two related but independent things:
 - limit the set of refs that are published (hide the uncooked topics)
 - remap the source and destination refs (e.g. push master to origin)

The first can be done by not having Push: at all and by solely relying on "matching refs" semantics. Then usually you can just keep doing "git push <destination>" until you have something new to add, at that point you say "git push <destination> <newbranch>" just once, and after that keep doing the "matching refs" push. You are having the remote repository remember what the set of refs you would want there, instead of listing them on the local "Push:" lines. All should work well that way.

I use Push: lines to push into my private, non-bare, repository at kernel.org machines for the second reason. I have:

	Push: heads/master:heads/origin
        Push: heads/next:heads/next
        Push: +heads/pu:heads/pu
        Push: heads/maint:heads/maint

and leave the "master" branch checked out over there. After pushing, I log-in, and start my work by "git pull . origin".

The "matching refs" feature actively does a wrong thing to remote repositories managed this way.

-- >8 -- [PATCH] git push --common <repo>

If you usually push only specific branches, it is handy to have
Push: lines only for those branches in your remotes/<repo> file.
But with that, you cannot access the underlying git-send-pack's
ability to push "only matching refs".  The flag --common can be
given to ignore Push: lines and push only matching refs.
---
diff --git a/git-push.sh b/git-push.sh
index f10cadb..381b76f 100755
--- a/git-push.sh
+++ b/git-push.sh
@@ -11,6 +11,7 @@ has_exec=
 has_thin=--thin
 remote=
 do_tags=
+do_common=
 
 while case "$#" in 0) break ;; esac
 do
@@ -19,6 +20,8 @@ do
 		has_all=--all ;;
 	--tags)
 		do_tags=yes ;;
+	--common)
+		do_common=yes ;;
 	--force)
 		has_force=--force ;;
 	--exec=*)
@@ -45,10 +48,21 @@ esac
 . git-parse-remote
 remote=$(get_remote_url "$@")
 
-case "$has_all" in
---all)
+case "$has_all,$do_common" in
+--all,yes)
+	die "Both --common and --all given." ;;
+--all,)
 	set x ;;
-'')
+,yes)
+	case "$do_tags,$#" in
+	,1)
+		set x ;;
+	yes,*)
+		die "Both --common and --tags given." ;;
+	*)
+		die "Both --common and an explicit refspec given." ;;
+	esac ;;
+,)
 	case "$do_tags,$#" in
 	yes,1)
 		set x $(cd "$GIT_DIR/refs" && find tags -type f -print) ;;
Previous: Linus TorvaldsNext: Jeff Garzik
Message 8 of 9 in “git builtin "push"”
  1. git builtin "push"Linus Torvalds, Apr 30, 2006
  2. Junio C HamanoApr 30, 2006
  3. seanApr 30, 2006
  4. Jeff GarzikApr 30, 2006
  5. Linus TorvaldsApr 30, 2006
  6. seanApr 30, 2006
  7. Linus TorvaldsApr 30, 2006
  8. Junio C HamanoApr 30, 2006
  9. Jeff GarzikApr 30, 2006

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.