git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Yuri Kanivetsky <yuri.kanivetsky@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: push.default and "git push"
Date: Fri, 13 Dec 2024 14:20:06 +0200	[thread overview]
Message-ID: <CAMhVC3Ztem+620b2yEYuHKWFZ5rofx1VD2nyvSSP8N_TY6b6Lg@mail.gmail.com> (raw)
In-Reply-To: <xmqqo7sq4khb.fsf@gitster.g>

It's been a while :) but... I've been researching some aspects of how
git works, and stumbled upon this issue again.

I came up with the following explanation (of how `push.default =
matching` works):

> 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`):
>
> * First it chooses a remote:
>
>   * if the current branch has an upstream, it chooses the remote the upstream points to
>
>   * else if there's only one remote, it chooses this only remote
>
>   * else it chooses `origin` if it exists
>
>   * otherwise it fails
>
> * Then it pushes matching branches to the remote.
>
> * 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).
>
> * 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`.

More in the following gist:

https://gist.github.com/x-yuri/0ac53cb7999b3b0352c1ec0ac8f5f4cc

The description given in the documentation:

> 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).

One can sort of make an argument that the remote repository kind of
remembers the branches you push to it, but... if you delete the local
branch that you just pushed, does that make the remote repository
forget that you pushed the branch?.. The analogy is flawed. And
confusing, because it's not at all clear that the state is stored "by
the list of the branches".

Also a lot of aspects of how `push.default = matching` works are left out.

Regards,
Yuri

      reply	other threads:[~2024-12-13 12:20 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-28 21:32 push.default and "git push" Yuri Kanivetsky
2022-11-29  1:28 ` Junio C Hamano
2024-12-13 12:20   ` Yuri Kanivetsky [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMhVC3Ztem+620b2yEYuHKWFZ5rofx1VD2nyvSSP8N_TY6b6Lg@mail.gmail.com \
    --to=yuri.kanivetsky@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).