git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Bill Wallace <wayfarer3130@gmail.com>
To: Brian Lyles <brianmlyles@gmail.com>
Cc: phillip.wood@dunelm.org.uk,
	"Kristoffer Haugsbakk" <code@khaugsbakk.name>,
	git@vger.kernel.org, "Rubén Justo" <rjusto@gmail.com>
Subject: Re: Worktree shares a common remote with main checkout
Date: Wed, 3 Apr 2024 14:29:38 -0400	[thread overview]
Message-ID: <CA+2m0i_UaGsBGYt5=CDYP1q13G1m2dB47QfnQ46J7BX8yrX0-A@mail.gmail.com> (raw)
In-Reply-To: <17c2d5148e3afb10.70b1dd9aae081c6e.203dcd72f6563036@zivdesk>

Each branch has a parent origin/remote repository that it is directly
tracking (or not tracking), but there are other operations that
presume the name "origin" as the name - the two that I care about are:

git fetch
- this should be able to default fetch a remote associated with the worktree

git push (on a new branch)
says:
  git push --set-upstream origin testBranch

I want this to say
  git push --set-upstream project1-remote testBranch

instead.  Ideally, adding this automatically should set the upstream
remote to the specified upstream branch if that is configured (which I
never do, since I often switch the upstream).

Ideally supposing there are two branches  origin/main and
project1-remote/main, then doing:
git checkout main
in worktree project1 would checkout project1-remote/main
while doing it in the original checkout would checkout  origin/main

There is no change to the functionality of worktree branches, the only
change is the ability to store configuration values associated with a
worktree (not a branch, but the worktree itself), plus getting the
name "origin" from configuration instead of defaulting to "origin"

The setting `checkout.defaultRemote` is close - but I want that to be
something like:
worktree.<name>.remote=<value>
eg
worktree.project1.remote=project1-remote

and then:
git fetch
will fetch from project1-remote when in project1 worktree

With git push having auto setup remote, this will default to pushing a
branch testBranch to
project1-remote/testBranch
and without it being auto setup, will show the message:
"git push --set-upstream project1-remote testBranch"
as specified above.

git checkout nonLocalBranch
will first try to get nonLocalBranch from project1-remote, and only if
it is ambiguous on other systems would it complain.

Bill

On Wed, 3 Apr 2024 at 13:24, Brian Lyles <brianmlyles@gmail.com> wrote:
>
> Hi Bill,
>
> Phillip Wood wrote:
>
> > You can set a different default remote for "git pull" for each branch by
> > setting an upstream branch with "git branch --set-upstream-to" which
> > sets "branch.<name>.remote" and "branch.<name>.merge" or
> > "branch.<name>.rebase". You can also set a different remote to push to
> > by setting "branch.<name>.pushRemote" - see the "git config"
> > documentation. Would that help?
>
> Bill Wallace wrote:
>
> > It helps, and I do that, but I really want it associated with the
> > worktree so that I can work on projects for different vendors based on
> > a common open source framework.  What I'm trying to avoid is
> > accidentally committing a branch to the wrong vendor's stream or
> > mixing changes between streams.
>
> My understanding of worktrees has always been that they are simply a
> checkout of an arbitrary branch, and that branches themselves define
> their remote as Phillip noted.
>
> I'm struggling to reconcile this fact of a branch defining its remote
> with having a worktree also define the remote. How would this be
> expected to behave if you try to switch a worktree with some defined
> remote to a branch based on another remote? A warning or error?
>
> I am also wondering if an adjustment to your branch creation/management
> would solve this problem without needing such a significant change to
> the definition of a worktree.
>
> At the point of branch creation, the branch will track a specific remote
> based on the ref it's created from (assuming that ref is a remote
> tracking ref, and based on your `branch.autoSetupMerge`/whether
> `--track`/`--no-track` is used). The remote can be corrected after
> creation as Phillip noted.
>
> For example: My understanding is that if you were to set your
> `branch.autoSetupMerge` to `inherit`, then when you create a new branch
> it would inherit the remote tracking ref (and therefore the remote) from
> the branch that you create it from. This would be the case whether you
> specify a ref manually at the time of creation, or just omit it to
> create the branch from the current checked out branch. If the latter,
> then by creating new branches from within the worktree that you
> designated for a specific vendor/stream, you ensure that the new branch
> uses that same remote.
>
> Have you tried that approach? `branch.autoSetupMerge` has
> several other values to control this behavior as well though `inherit`
> seems closest to what you're looking for to me. If this is still
> insufficient, I'd be curious to hear more specifics about where it
> breaks down.
>
> --
> Thank you,
> Brian Lyles


      parent reply	other threads:[~2024-04-03 18:40 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-22 14:50 Worktree shares a common remote with main checkout Bill Wallace
2024-03-22 17:00 ` Rubén Justo
2024-03-22 17:15   ` Rubén Justo
2024-03-22 17:28 ` Kristoffer Haugsbakk
2024-04-03 14:26   ` Bill Wallace
2024-04-03 15:30     ` Phillip Wood
2024-04-03 16:18       ` Bill Wallace
     [not found]         ` <17c2d5148e3afb10.70b1dd9aae081c6e.203dcd72f6563036@zivdesk>
2024-04-03 18:29           ` Bill Wallace [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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to='CA+2m0i_UaGsBGYt5=CDYP1q13G1m2dB47QfnQ46J7BX8yrX0-A@mail.gmail.com' \
    --to=wayfarer3130@gmail.com \
    --cc=brianmlyles@gmail.com \
    --cc=code@khaugsbakk.name \
    --cc=git@vger.kernel.org \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=rjusto@gmail.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).