git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Cyrus Vafadari <cvafadari@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Git Checkout tracking behavior with <start_point>?
Date: Thu, 4 Nov 2021 06:17:33 -0400	[thread overview]
Message-ID: <YYOzPVi5TAoyGNAs@coredump.intra.peff.net> (raw)
In-Reply-To: <CAMd+_QCDN5UwwC=ZRcT4Y3p1x7kCQ1TEVf5321Ykx4xrhv-YOA@mail.gmail.com>

On Wed, Nov 03, 2021 at 11:08:29AM -0400, Cyrus Vafadari wrote:

> I am an avid user of this pattern: "git checkout -b my_branch
> upstream/3.2.x", using "start_point" to build my backported patch
> against an old feature version. But in this case, the default tracking
> is against 3.2.x, rather than my new feature branch. So, then, when I
> push I specify to update the tracking against the new branch name.
> There are also various default behaviors for push, which I won't
> enumerate here, but in the end I need to specify tracking.
> 
> I'm wondering if there is some usage/pattern I'm missing?

I think it all depends on your workflows and how you use the upstream
information. For instance, I start most of my branches off of the tip of
the remote master, similar to you:

  git checkout -b my-topic origin/master

I want to keep that as the upstream for various commands. E.g.,
"git-rebase -i" will use the fork point of the branch by default,
without even having to say "@{upstream}".

When I push, it goes to a remote branch with a matching name (because I
have push.default set to "current"). If I want to look at the
remote-repo version (say, to compare what's happened since I last
pushed), I use the "@{push}" shortcut to refer to it (rather than
"@{upstream}"). So for example I often do:

  git range-diff @{push}...HEAD

to see what hasn't yet been pushed (range-diff rather than a regular
"log" because I'm usually rewriting commits via rebase).

Now that's just what _I_ do. There's nothing wrong with setting the
upstream to the push destination if your workflows prefer that (e.g.,
because you are collaborating with somebody else on the branch and want
to be able to pull or rebase just the parts that haven't been pushed).
And that's why we have "push -u".

But no, I don't think there's a way to set the upstream to that push
destination at the time you run "git checkout". I don't think it would
be an unreasonable config option to have. Once upon a time it was very
tricky to say "the thing that I would push to by default", because those
rules were all just encoded inside of git-push. But these days you
should be able to reuse the logic that powers @{push}.

-Peff

      parent reply	other threads:[~2021-11-04 10:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-03 15:08 Git Checkout tracking behavior with <start_point>? Cyrus Vafadari
2021-11-03 20:17 ` Stefan Moch
2021-11-04 10:17 ` Jeff King [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=YYOzPVi5TAoyGNAs@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=cvafadari@gmail.com \
    --cc=git@vger.kernel.org \
    /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).