vscode-gitlens icon indicating copy to clipboard operation
vscode-gitlens copied to clipboard

Prompt for setting upstream when creating a local branch off a remote branch

Open jkelroy opened this issue 2 years ago • 3 comments

Currently, when creating a branch from a remote only branch - on the commit graph or from the remotes sideview - GitLens will automatically set the upstream to that remote branch in the ~\repo.git\config. However, there is no indication that this is being done.

It would be nice if GitLens prompted the user that the upstream was being set on branch creation or on push.

Notable, if you create a branch off a local and remote branch (pointing to the same commit) the upstream is not set automatically. This seems inconsistent with the above behavior.

Screenshot 2023-06-29 at 8 33 01 AM Screenshot 2023-06-29 at 8 34 27 AM

jkelroy avatar Jun 30 '23 16:06 jkelroy

I have observed this behavior. This has caused me confusion before, and it would have caused me trouble if I didn't have branch protection rules in place to stop me.

The menu option reads "Create Branch...", so it is more intuitive to me if the newly created branch was not set to track any remote branch. Instead, I feel like that might be the correct behavior of selecting "Rename Branch..." on a remote branch. I would also be satisfied, however, with a prompt to choose the remote tracking branch upon creation, as OP suggests.

grantg-ht avatar Sep 05 '23 18:09 grantg-ht

I just realized that this behavior is in Git, under branch.autoSetupMerge. I ran this and now I get new branches with no remote tracking branch, just how I like it:

sudo git config --system branch.autoSetupMerge simple

grantg-ht avatar Sep 27 '23 16:09 grantg-ht

This is quite unintuitive. I am sure in 99% of all cases when a user creates a branch (by giving it a custom name), he expects it to not track anything and then be able to publish the branch instead of it just tracking the branch it was created from.

  • When using VSCode Git: Create Branch From... command, it does exactly that (no tracking).
  • When using GitLens GitLens: Git Create Branch... command, it also works correctly (no tracking).
  • When using GitLens Create Branch via context menu in the Branches view, it does add the tracking to the source branch

So basically, the context menu Create Branch just seems to be not consistent with the rest and should imho be adjusted to behave as the commands from VSCode or even GitLens.

Edit: I guess this issue is related to https://github.com/gitkraken/vscode-gitlens/issues/1805 and https://github.com/gitkraken/vscode-gitlens/issues/1599 and a pending PR https://github.com/gitkraken/vscode-gitlens/pull/1817

Roemer avatar Jun 11 '24 10:06 Roemer