Skip to content

Adds ability to set or change the upstream branch for branches #4499

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
- Adds a new "Favorited Branches" option to the branches visibility dropdown on the _Commit Graph_
- Adds _Add to Favorites_ or _Remove from Favorites_ context menu items to branches in the _Commit Graph_
- Adds _Add to Favorites_ or _Remove from Favorites_ context menu items to worktrees in the views
- Adds ability to set or change the upstream branch for branches in the _Commit Graph_ and other GitLens views ([#4498](https://github.com/gitkraken/vscode-gitlens/issues/4498))
- Adds new _Set Upstream..._ and _Change Upstream..._ context menu items to branches in the _Commit Graph_ and other GitLens views
- Adds a new _upstream_ sub-command to the _branch_ Git Command Palette

### Changed

Expand Down
56 changes: 56 additions & 0 deletions contributions.json
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,34 @@
"label": "Change Branch Merge Target",
"commandPalette": "gitlens:enabled && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders"
},
"gitlens.changeUpstream:graph": {
"label": "Change Upstream...",
"icon": "$(link)",
"enablement": "!operationInProgress",
"menus": {
"webview/context": [
{
"when": "webviewItem =~ /gitlens:branch\\b(?!.*?\\b\\+remote\\b)(?!.*?\\b\\+closed\\b)(?=.*?\\b\\+tracking\\b)/ && !listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
"group": "1_gitlens_actions_2",
"order": 3
}
]
}
},
"gitlens.changeUpstream:views": {
"label": "Change Upstream...",
"icon": "$(link)",
"enablement": "!operationInProgress",
"menus": {
"view/item/context": [
{
"when": "viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+remote\\b)(?!.*?\\b\\+closed\\b)(?=.*?\\b\\+tracking\\b)/ && !listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
"group": "1_gitlens_actions_2",
"order": 3
}
]
}
},
"gitlens.clearFileAnnotations": {
"label": "Clear File Annotations",
"icon": "$(gitlens-gitlens-filled)",
Expand Down Expand Up @@ -3776,6 +3804,34 @@
]
}
},
"gitlens.setUpstream:graph": {
"label": "Set Upstream...",
"icon": "$(link)",
"enablement": "!operationInProgress",
"menus": {
"webview/context": [
{
"when": "webviewItem =~ /gitlens:branch\\b(?!.*?\\b\\+remote\\b)(?!.*?\\b\\+closed\\b)(?!.*?\\b\\+tracking\\b)/ && !listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
"group": "1_gitlens_actions_2",
"order": 3
}
]
}
},
"gitlens.setUpstream:views": {
"label": "Set Upstream...",
"icon": "$(link)",
"enablement": "!operationInProgress",
"menus": {
"view/item/context": [
{
"when": "viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+remote\\b)(?!.*?\\b\\+closed\\b)(?!.*?\\b\\+tracking\\b)/ && !listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
"group": "1_gitlens_actions_2",
"order": 3
}
]
}
},
"gitlens.shareAsCloudPatch": {
"label": "Share as Cloud Patch...",
"commandPalette": "gitlens:enabled && gitlens:gk:organization:drafts:enabled && config.gitlens.cloudPatches.enabled",
Expand Down
2 changes: 1 addition & 1 deletion docs/telemetry-events.md

Large diffs are not rendered by default.

60 changes: 60 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6358,6 +6358,18 @@
"title": "Change Branch Merge Target",
"category": "GitLens"
},
{
"command": "gitlens.changeUpstream:graph",
"title": "Change Upstream...",
"icon": "$(link)",
"enablement": "!operationInProgress"
},
{
"command": "gitlens.changeUpstream:views",
"title": "Change Upstream...",
"icon": "$(link)",
"enablement": "!operationInProgress"
},
{
"command": "gitlens.clearFileAnnotations",
"title": "Clear File Annotations",
Expand Down Expand Up @@ -7595,6 +7607,18 @@
"title": "Reveal Commit in Side Bar",
"category": "GitLens"
},
{
"command": "gitlens.setUpstream:graph",
"title": "Set Upstream...",
"icon": "$(link)",
"enablement": "!operationInProgress"
},
{
"command": "gitlens.setUpstream:views",
"title": "Set Upstream...",
"icon": "$(link)",
"enablement": "!operationInProgress"
},
{
"command": "gitlens.shareAsCloudPatch",
"title": "Share as Cloud Patch...",
Expand Down Expand Up @@ -10899,6 +10923,14 @@
"command": "gitlens.changeBranchMergeTarget",
"when": "gitlens:enabled && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders"
},
{
"command": "gitlens.changeUpstream:graph",
"when": "false"
},
{
"command": "gitlens.changeUpstream:views",
"when": "false"
},
{
"command": "gitlens.clearFileAnnotations",
"when": "resource in gitlens:tabs:blameable && (gitlens:window:annotated || resource in gitlens:tabs:annotated)"
Expand Down Expand Up @@ -11859,6 +11891,14 @@
"command": "gitlens.revealCommitInView",
"when": "resource in gitlens:tabs:blameable"
},
{
"command": "gitlens.setUpstream:graph",
"when": "false"
},
{
"command": "gitlens.setUpstream:views",
"when": "false"
},
{
"command": "gitlens.shareAsCloudPatch",
"when": "gitlens:enabled && gitlens:gk:organization:drafts:enabled && config.gitlens.cloudPatches.enabled"
Expand Down Expand Up @@ -16923,6 +16963,16 @@
"when": "viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+closed\\b)/ && !listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
"group": "1_gitlens_actions_2@2"
},
{
"command": "gitlens.changeUpstream:views",
"when": "viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+remote\\b)(?!.*?\\b\\+closed\\b)(?=.*?\\b\\+tracking\\b)/ && !listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
"group": "1_gitlens_actions_2@3"
},
{
"command": "gitlens.setUpstream:views",
"when": "viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+remote\\b)(?!.*?\\b\\+closed\\b)(?!.*?\\b\\+tracking\\b)/ && !listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
"group": "1_gitlens_actions_2@3"
},
{
"command": "gitlens.views.deleteBranch",
"when": "viewItem =~ /gitlens:branch\\b(?!.*?\\b\\+current\\b)(?!.*?\\b\\+closed\\b)/ && !listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
Expand Down Expand Up @@ -22755,11 +22805,21 @@
"when": "webviewItem =~ /gitlens:branch\\b/ && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
"group": "1_gitlens_actions_2@2"
},
{
"command": "gitlens.changeUpstream:graph",
"when": "webviewItem =~ /gitlens:branch\\b(?!.*?\\b\\+remote\\b)(?!.*?\\b\\+closed\\b)(?=.*?\\b\\+tracking\\b)/ && !listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
"group": "1_gitlens_actions_2@3"
},
{
"command": "gitlens.graph.deleteBranch",
"when": "webviewItem =~ /gitlens:branch\\b(?!.*?\\b\\+(current|checkedout)\\b)/ && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
"group": "1_gitlens_actions_2@3"
},
{
"command": "gitlens.setUpstream:graph",
"when": "webviewItem =~ /gitlens:branch\\b(?!.*?\\b\\+remote\\b)(?!.*?\\b\\+closed\\b)(?!.*?\\b\\+tracking\\b)/ && !listMultiSelection && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
"group": "1_gitlens_actions_2@3"
},
{
"command": "gitlens.graph.createBranch",
"when": "webviewItem =~ /gitlens:branch\\b/ && !gitlens:readonly && !gitlens:untrusted && !gitlens:hasVirtualFolders",
Expand Down
14 changes: 9 additions & 5 deletions src/commands/changeBranchMergeTarget.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ThemeIcon } from 'vscode';
import type { Container } from '../container';
import type { GitBranch } from '../git/models/branch';
import type { Repository } from '../git/models/repository';
Expand Down Expand Up @@ -92,11 +93,14 @@ export class ChangeBranchMergeTargetCommand extends QuickCommand {
picked: state.mergeBranch,
placeholder: 'Pick a merge target branch',
filter: (branch: GitBranch) => branch.remote && branch.name !== state.branch,
reset: {
allowed: userMergeTarget != null && detectedMergeTarget !== userMergeTarget,
label: 'Reset Merge Target',
detail: 'Reset the merge target branch to be automatically detected',
},
reset:
userMergeTarget != null && detectedMergeTarget !== userMergeTarget
? {
label: 'Reset Merge Target',
detail: 'Reset the merge target branch to be automatically detected',
button: { icon: new ThemeIcon('discard'), tooltip: 'Reset Merge Target' },
}
: undefined,
});
if (result === StepResultBreak) continue;

Expand Down
Loading