{"thread":{"id":"58867","subject":"push.default and \"git push\"","startedAt":"2022-11-28T21:32:23Z","lastAt":"2024-12-13T12:20:19Z","messageCount":3,"participants":["Yuri Kanivetsky","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"468127","messageId":"CAMhVC3ZHsGJs8XJPZOPYCWBCHJOkp8xnau=5xH_Bj33JUZ4DNA@mail.gmail.com","threadId":"58867","inReplyTo":null,"subject":"push.default and \"git push\"","fromName":"Yuri Kanivetsky","fromEmail":"yuri.kanivetsky@gmail.com","sentAt":"2022-11-28T21:32:04Z","receivedAt":"2022-11-28T21:32:23Z","isPatch":false,"sender":{"key":"yuri.kanivetsky@gmail.com","avatar":"https://gravatar.com/avatar/e4d91cf41e555a0c340222a1898c6320f51ad5ab2f9638282cc2412abb450648?d=mp&s=160"},"body":"Hi,\n\nI've been reading the documentation on git push lately, and there are\na couple of places I don't quite understand. From git-config:\n\n> matching - push all branches having the same name on both ends. This makes the repository you are pushing to remember the set of branches that will be pushed out (e.g. if you always push maint and master there and no other branches, the repository you push to will have these two branches, and your local maint and master will be pushed there).\n\n(1) What does \"remember\" exactly mean? Is this a round-about way to\nsay that when you push a branch it gets created? But no, it won't push\na branch, unless it exists remotely.\n\nActually I created a script to examine how these modes work:\n\nhttps://gist.github.com/x-yuri/20f24f628db1bcbf272c055b33c18889\n\nAnd from git-push:\n\n> When the command line does not specify where to push with the <repository> argument, branch.*.remote configuration for the current branch is consulted to determine where to push. If the configuration is missing, it defaults to origin.\n\nI've found that if there's no remote named \"origin\" it pushes to the\nfirst remote. Or so it seems:\n\nhttps://gist.github.com/x-yuri/888261d182fdab92040760138ea10a22\n\n(2) I wonder if the documentation should be amended...\n\nRegards,\nYuri\n"},{"id":"468144","messageId":"xmqqo7sq4khb.fsf@gitster.g","threadId":"58867","inReplyTo":"CAMhVC3ZHsGJs8XJPZOPYCWBCHJOkp8xnau=5xH_Bj33JUZ4DNA@mail.gmail.com","subject":"Re: push.default and \"git push\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-11-29T01:28:48Z","receivedAt":"2022-11-29T01:28:53Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Yuri Kanivetsky <yuri.kanivetsky@gmail.com> writes:\n\n> (1) What does \"remember\" exactly mean?\n\nBecause your matching push updates only the branches that exist at\nthe receiving repository, you do not have to remember in your head\nwhich branches you want to keep updating over there and write them\non your command line (i.e. \"git push there this-branch\" to update\n\"this-branch\" in \"there\" repository).\n\nYou do not have to ask your configuration file to remember\n(i.e. [remote \"there\"] push = refs/heads/this-branch), either.\n\nWithout having to make an active effort to \"remember\" on your side,\n\"git push there\" would notice that they have this-branch (because\nyou pushed there the last time to create it) and you have updated\nthis-branch on your end, and update that branch.\n\nThat is what the verb \"remember\" refers to in that sentence.\n"},{"id":"509097","messageId":"CAMhVC3Ztem+620b2yEYuHKWFZ5rofx1VD2nyvSSP8N_TY6b6Lg@mail.gmail.com","threadId":"58867","inReplyTo":"xmqqo7sq4khb.fsf@gitster.g","subject":"Re: push.default and \"git push\"","fromName":"Yuri Kanivetsky","fromEmail":"yuri.kanivetsky@gmail.com","sentAt":"2024-12-13T12:20:06Z","receivedAt":"2024-12-13T12:20:19Z","isPatch":false,"sender":{"key":"yuri.kanivetsky@gmail.com","avatar":"https://gravatar.com/avatar/e4d91cf41e555a0c340222a1898c6320f51ad5ab2f9638282cc2412abb450648?d=mp&s=160"},"body":"It's been a while :) but... I've been researching some aspects of how\ngit works, and stumbled upon this issue again.\n\nI came up with the following explanation (of how `push.default =\nmatching` works):\n\n> In this mode `git push` pushes matching branches, i.e. all local branches that exist in a remote, to their remote counterparts (if there's a local branch `ba` and a remote branch `origin/ba`, it pushes `ba` to `origin/ba`):\n>\n> * First it chooses a remote:\n>\n>   * if the current branch has an upstream, it chooses the remote the upstream points to\n>\n>   * else if there's only one remote, it chooses this only remote\n>\n>   * else it chooses `origin` if it exists\n>\n>   * otherwise it fails\n>\n> * Then it pushes matching branches to the remote.\n>\n> * If the upstream of the current branch is in the local repo, there can be no matching branches by definition (there can't be 2 branches with the same name in a repository).\n>\n> * It never chooses a non-matching branch, even if it's an upstream. If `ba` has an upstream `origin/ba2` and there's `origin/ba`, it will choose `origin/ba`.\n\nMore in the following gist:\n\nhttps://gist.github.com/x-yuri/0ac53cb7999b3b0352c1ec0ac8f5f4cc\n\nThe description given in the documentation:\n\n> matching - push all branches having the same name on both ends. This makes the repository you are pushing to remember the set of branches that will be pushed out (e.g. if you always push maint and master there and no other branches, the repository you push to will have these two branches, and your local maint and master will be pushed there).\n\nOne can sort of make an argument that the remote repository kind of\nremembers the branches you push to it, but... if you delete the local\nbranch that you just pushed, does that make the remote repository\nforget that you pushed the branch?.. The analogy is flawed. And\nconfusing, because it's not at all clear that the state is stored \"by\nthe list of the branches\".\n\nAlso a lot of aspects of how `push.default = matching` works are left out.\n\nRegards,\nYuri\n"}]}