Skip to content

Add restore deleted branches and their upstreams - #5887

Open
borngraced wants to merge 10 commits into
jesseduffield:masterfrom
borngraced:restore-deleted-branch
Open

Add restore deleted branches and their upstreams#5887
borngraced wants to merge 10 commits into
jesseduffield:masterfrom
borngraced:restore-deleted-branch

Conversation

@borngraced

Copy link
Copy Markdown

PR Description

Please check if the PR fulfills these requirements

  • Cheatsheets are up-to-date (run go generate ./...)
  • Code has been formatted (see here)
  • Tests have been added/updated (see here for the integration test guide)
  • Text is internationalised (see here)
  • If a new UserConfig entry was added, make sure it can be hot-reloaded (see here)
  • Docs have been updated if necessary
  • You've read through your own file changes for silly mistakes etc

Adds two related capabilities for recovering branches that no longer show up in the branch list:

  1. Restore deleted local branches: Branches deleted in lazygit are now detected via the reflog and listed in the branch panel with a "deleted branch" badge. A new keybinding (<ctrl+r> in the branches panel) opens a menu to recreate the selected deleted branch at its last commit. If exactly one matching remote-tracking ref survives, the upstream is re-attached automatically.
  2. Restore deleted remote branches: When a branch's remote was deleted (e.g. on GitHub) and the local branch shows "(upstream gone)", a new "Restore upstream branch" item in the upstream options menu (u → p) pushes the local branch back to its configured remote, recreating the branch and clearing the gone state.

Includes unit tests for deleted-branch detection (with hardening against reflog noise like SHA-like refs and orphaned checkout entries) plus integration tests covering both the delete-and-restore flow and the upstream-gone restore.

@borngraced
borngraced force-pushed the restore-deleted-branch branch from c7d50d9 to e3cab97 Compare August 3, 2026 12:09
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.

1 participant