Skip to content

feat: pin/unpin git branches in Git: Checkout#319214

Open
TomasMartinsFerreira wants to merge 1 commit into
microsoft:mainfrom
Diogo7Matias:pin-branch-feature
Open

feat: pin/unpin git branches in Git: Checkout#319214
TomasMartinsFerreira wants to merge 1 commit into
microsoft:mainfrom
Diogo7Matias:pin-branch-feature

Conversation

@TomasMartinsFerreira
Copy link
Copy Markdown

Closes #285828

Issue

Issue #285828 requests a feature that allows users to pin and unpin branches in VS Code. This feature should also include a clear visual distinction between pinned and unpinned branches.

Solution

We added a button to each branch item in the Git: Checkout interface that allows users to pin and unpin their git branches. Pinned branches appear at the top with an additional icon for visual distinction.

The following commands were also created to allow for quicker pinning/unpinning (executable from the command palette):

  • Git: Pin Branch
  • Git: Unpin Branch
  • Git: Pin Current Branch

We added a button to each branch item in the Git: Checkout interface
that allows users to pin and unpin their git branches.
Pinned branches appear at the top with an additional icon for visual
distinction.

The following commands were also created to allow for quicker
pinning/unpinning (executable from the command palette):
 - Git: Pin Branch
 - Git: Unpin Branch
 - Git: Pin Current Branch

Closes microsoft#285828

Co-authored-by: Tomás Ferreira <tomasmartinsferreira@tecnico.ulisboa.pt>
Copilot AI review requested due to automatic review settings May 31, 2026 19:44
@vs-code-engineering
Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@lszomoru

Matched files:

  • extensions/git/package.json
  • extensions/git/package.nls.json
  • extensions/git/src/commands.ts
  • extensions/git/src/repository.ts
  • extensions/git/src/test/repository.test.ts

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds the ability to pin/unpin Git branches so that they appear at the top of the branch picker for quick access. Pinned branches are persisted per-repository in globalState, exposed via three new commands, and surfaced in the existing checkout quick pick with inline pin/unpin buttons.

Changes:

  • Adds pinBranch/unpinBranch/isBranchPinned APIs on Repository, persisted under pinnedBranches:<root> in globalState, and auto-unpins when a branch is deleted.
  • Updates the checkout quick pick to render a PinnedCheckoutItem, group pinned branches under a "pinned" separator, and provide inline pin/unpin buttons that refresh the pick in place.
  • Adds three new commands (git.pinBranch, git.unpinBranch, git.pinCurrentBranch) with corresponding NLS entries, plus tests for the pinning logic.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
extensions/git/src/repository.ts Implements pin/unpin storage and unpins on branch deletion.
extensions/git/src/commands.ts Adds pinned UI, inline buttons, separator grouping, and new commands.
extensions/git/package.json Registers the three new pin-related commands.
extensions/git/package.nls.json Adds command titles for pin/unpin commands.
extensions/git/src/test/repository.test.ts Adds tests for branch pinning behavior.

Comment on lines +3398 to +3401
const pinnedBranches = this.getPinnedBranches();
pinnedBranches.push(branch);

this.globalState.update(this.getPinnedBranchesStorageKey(), pinnedBranches);
const pinnedBranches = this.getPinnedBranches();
pinnedBranches.push(branch);

this.globalState.update(this.getPinnedBranchesStorageKey(), pinnedBranches);
Comment on lines +664 to +669
icon: isPinned
? 'star-full'
: 'star-empty',
label: isPinned
? 'Unpin Branch'
: 'Pin Branch',
Comment on lines +706 to +708
return pinned.length === 0
? result
: [new RefItemSeparator(undefined, 'pinned'), ...pinned, ...unpinned];
Comment on lines +172 to +175
constructor(override readonly ref: Branch, shortCommitLength: number, private readonly inner: CheckoutItem) {
super(ref, shortCommitLength);
this.inner = inner;
}
Comment on lines +2987 to +2997
disposables.push((quickPick.onDidTriggerItemButton(async (e) => {
const item = e.item as CheckoutItem;
if (button.actual && item.refName) {
button.actual.run(item.refRemote ? item.refName.substring(item.refRemote.length + 1) : item.refName);
const button = e.button as QuickInputButton & {
actual: RemoteSourceAction | PinBranchAction;
};

if (!button.actual || !item.refName) {
return;
}

button.actual.run(item.refRemote ? item.refName.substring(item.refRemote.length + 1) : item.refName);
Comment on lines +50 to +60
function createRepository(root: string, globalState: Memento): Repository {
const repository = Object.create(Repository.prototype) as Record<string, unknown>;
repository.repository = {
root,
rootRealPath: undefined,
dotGit: undefined,
kind: 'repository'
};
repository.globalState = globalState;
return repository as unknown as Repository;
}
@TomasMartinsFerreira
Copy link
Copy Markdown
Author

@TomasMartinsFerreira please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

@microsoft-github-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow Pin or Favorite Branches in Git Checkout Panel

4 participants