From 2978aeeeb3781a4b0a320baf5454a243b1a25ac0 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Thu, 23 Apr 2026 15:51:57 -0400 Subject: [PATCH] Add a `git: copy branch name` action (#54702) I frequently use the branch name copy action in GitHub Desktop. I want to do this in Zed. Self-Review Checklist: - [X] I've reviewed my own diff for quality, security, and reliability - [X] Unsafe blocks (if any) have justifying comments - [X] The content is consistent with the [UI/UX checklist](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist) - [ ] Tests cover the new/changed behavior - [X] Performance impact has been considered and is acceptable Release Notes: - Added a `git: copy branch name` action. --- crates/git/src/git.rs | 2 ++ crates/git_ui/src/git_ui.rs | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/crates/git/src/git.rs b/crates/git/src/git.rs index d965605fe0..debb7649ab 100644 --- a/crates/git/src/git.rs +++ b/crates/git/src/git.rs @@ -105,6 +105,8 @@ actions!( ViewCommit, /// Adds a file to .gitignore. AddToGitignore, + /// Copies the current branch name to the clipboard. + CopyBranchName, ] ); diff --git a/crates/git_ui/src/git_ui.rs b/crates/git_ui/src/git_ui.rs index 0b44b1c517..5aa6ffe782 100644 --- a/crates/git_ui/src/git_ui.rs +++ b/crates/git_ui/src/git_ui.rs @@ -17,8 +17,8 @@ use git::{ status::{FileStatus, StatusCode, UnmergedStatus, UnmergedStatusCode}, }; use gpui::{ - App, Context, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, SharedString, - Subscription, Task, Window, + App, ClipboardItem, Context, DismissEvent, Entity, EventEmitter, FocusHandle, Focusable, + SharedString, Subscription, Task, Window, }; use menu::{Cancel, Confirm}; use project::git_store::Repository; @@ -270,6 +270,9 @@ pub fn init(cx: &mut App) { workspace.register_action(|workspace, _: &git::RenameBranch, window, cx| { rename_current_branch(workspace, window, cx); }); + workspace.register_action(|workspace, _: &git::CopyBranchName, _, cx| { + copy_branch_name(workspace, cx); + }); workspace.register_action(show_ref_picker); workspace.register_action( |workspace, action: &DiffClipboardWithSelectionData, window, cx| { @@ -465,6 +468,20 @@ fn rename_current_branch( }); } +fn copy_branch_name(workspace: &mut Workspace, cx: &mut Context) { + let Some(panel) = workspace.panel::(cx) else { + return; + }; + let branch_name = panel.update(cx, |panel, cx| { + let repo = panel.active_repository.as_ref()?; + let repo = repo.read(cx); + repo.branch.as_ref().map(|branch| branch.name().to_string()) + }); + if let Some(name) = branch_name { + cx.write_to_clipboard(ClipboardItem::new_string(name)); + } +} + struct RefPickerModal { editor: Entity, repo: Entity,