Skip to content

feat: add mv/rename command for worktree renaming#95

Merged
helizaga merged 5 commits intocoderabbitai:mainfrom
kawarimidoll:feat/mv-rename-command
Feb 2, 2026
Merged

feat: add mv/rename command for worktree renaming#95
helizaga merged 5 commits intocoderabbitai:mainfrom
kawarimidoll:feat/mv-rename-command

Conversation

@kawarimidoll
Copy link
Contributor

@kawarimidoll kawarimidoll commented Feb 1, 2026

Pull Request

Description

Add git gtr mv (alias: git gtr rename) command to rename both the worktree directory and its associated branch in a single operation.

Features:

  • Renames branch with git branch -m
  • Moves worktree directory with git worktree move
  • Rollback on failure (restores branch name if move fails)
  • Warns about remaining remote branches
  • Supports --force flag for locked worktrees

Motivation

Fixes #93

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring (no functional changes)
  • Other (please describe):

Testing

Manual Testing Checklist

Tested on:

  • macOS
  • Linux (specify distro: **_**)
  • Windows (Git Bash)

Core functionality tested:

  • git gtr new <branch> - Create worktree
  • git gtr go <branch> - Navigate to worktree
  • git gtr editor <branch> - Open in editor (if applicable)
  • git gtr ai <branch> - Start AI tool (if applicable)
  • git gtr rm <branch> - Remove worktree
  • git gtr list - List worktrees
  • git gtr config - Configuration commands (if applicable)
  • Other commands affected by this change: git gtr mv, git gtr rename

Test Steps

  1. Create a worktree: git gtr new test-old-name
  2. Rename it: git gtr mv test-old-name test-new-name
  3. Verify branch renamed: git branch | grep test-new-name
  4. Verify directory moved: git gtr list
  5. Test error cases: git gtr mv 1 new-name (should reject)
  6. Test alias: git gtr rename test-new-name another-name
  7. Clean up: git gtr rm another-name

Expected behavior: Worktree directory and branch both renamed

Actual behavior: Works as expected

Breaking Changes

  • This PR introduces breaking changes
  • I have discussed this in an issue first
  • Migration guide is included in documentation

Note: This PR also updates the documented minimum Git version from 2.5+ to 2.17+. This is not a new requirement - the existing git gtr rm command already uses git worktree remove which requires Git 2.17+.

Checklist

Before submitting this PR, please check:

  • I have read CONTRIBUTING.md
  • My code follows the project's style guidelines
  • I have performed manual testing on at least one platform
  • I have updated documentation (README.md, CLAUDE.md, etc.) if needed
  • My changes work on multiple platforms (or I've noted platform-specific behavior)
  • I have added/updated shell completions (if adding new commands or flags)
  • I have tested with both git gtr (production) and ./bin/gtr (development)
  • No new external dependencies are introduced (Bash + git only)
  • All existing functionality still works

Additional Context

Test environment: macOS, Git 2.52.0, Bash 5.3.9


License Acknowledgment

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache License 2.0.

Summary by CodeRabbit

  • New Features

    • Added git gtr mv (alias rename) to rename a worktree and its local branch, with optional --force/--yes flags.
  • Documentation

    • Updated minimum Git requirement from 2.5+ to 2.17+ and refreshed docs/tables to reflect move/remove support.
    • Added command reference and examples for mv/rename.
  • Chores

    • Updated shell completions (bash, fish, zsh) to support mv/rename.
  • Tests

    • Added test flows covering mv/rename, conflict handling, and copy patterns.

kawarimidoll and others added 3 commits February 1, 2026 18:25
Add `git gtr mv` (alias: `git gtr rename`) command to rename both the
worktree directory and its associated branch in a single operation.

Features:
- Renames branch with `git branch -m`
- Moves worktree directory with `git worktree move`
- Rollback on failure (restores branch name if move fails)
- Warns about remaining remote branches
- Supports --force flag for locked worktrees

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add documentation for the new `git gtr mv` command in the Commands
section of README.md.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
The codebase uses `git worktree remove` and `git worktree move` which
were introduced in Git 2.17 (April 2018). The previous documentation
incorrectly stated Git 2.5+ as the minimum requirement.

Updated:
- README.md badge and requirements section
- CLAUDE.md version compatibility section
- docs/troubleshooting.md version support table

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Feb 1, 2026

Walkthrough

Added a new mv/rename subcommand to git gtr that renames a worktree directory and its local branch atomically; updated minimum Git requirement to 2.17+ and adjusted documentation and shell completions to expose the new command and flags.

Changes

Cohort / File(s) Summary
Documentation & Versioning
CLAUDE.md, README.md, docs/troubleshooting.md
Bumped minimum Git requirement from 2.5+ to 2.17+, adjusted fallback/version tables, and documented the new git gtr mv <old> <new> [--force] (alias rename) command with examples and notes.
Command Implementation
bin/gtr
Added cmd_rename() implementing atomic rename of worktree directory and associated local branch with validation, conflict checks, move operation (with --force), rollback on failure, confirmations, and progress/error reporting. Dispatcher updated to handle mv and rename.
Shell Completions
completions/_git-gtr, completions/git-gtr.fish, completions/gtr.bash
Added mv and rename to subcommand lists and completions, added --force and --yes flags for the new commands, and wired branch/worktree-name completion helpers for argument suggestions.

Sequence Diagram

sequenceDiagram
    actor User
    participant CLI as git gtr
    participant Branch as git branch
    participant Worktree as git worktree

    User->>CLI: git gtr mv old-name new-name [--force] [--yes]
    CLI->>CLI: validate inputs & resolve worktree
    CLI->>CLI: check conflicts (paths & branches)
    CLI->>Branch: git branch -m old-name new-name
    activate Branch
    Branch-->>CLI: success
    deactivate Branch
    CLI->>Worktree: git worktree move [--force] old-path new-path
    activate Worktree
    alt move succeeds
        Worktree-->>CLI: success
        CLI-->>User: renamed successfully
    else move fails
        Worktree-->>CLI: error
        CLI->>Branch: git branch -m new-name old-name  (rollback)
        activate Branch
        Branch-->>CLI: rollback complete
        deactivate Branch
        CLI-->>User: error + rollback notice
    end
    deactivate Worktree
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 I hopped from branch to path anew,
With mv I tied the twine—two into true.
One little command, a tidy little shove,
Branch and worktree snug as a glove. 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding a new mv/rename command for worktree renaming, which aligns with the primary objective of the PR.
Linked Issues check ✅ Passed All coding requirements from issue #93 are met: mv/rename command implementation [#93], branch rename via git branch -m [#93], worktree move via git worktree move [#93], rollback on failure [#93], --force flag support [#93], and comprehensive documentation/completions updates.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the mv/rename command: bin/gtr adds the core command, documentation files explain the feature, completion files support the command, and version requirements are appropriately updated for git worktree move/remove support.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

- Remove -f short flag (inconsistent with other commands)
- Add --yes flag and confirmation prompt before rename
- Use git -C "$repo_root" for all git commands (safe when cwd != repo root)
- Replace unquoted $force_flag with proper array pattern
- Remove dead "." / ".." validation (sanitize_branch_name prevents these)
- Update help text, README, completions, and CLAUDE.md test steps
@helizaga helizaga merged commit 923f580 into coderabbitai:main Feb 2, 2026
1 check passed
@kawarimidoll kawarimidoll deleted the feat/mv-rename-command branch February 3, 2026 03:48
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.

feat: add mv/rename command for worktree renaming

2 participants