A comprehensive Gerrit plugin for renaming Git branches while automatically handling all associated changes.
The Rename Branch plugin provides a safe and efficient way to rename branches in Gerrit projects. It automatically moves all changes (both open and closed) from the source branch to the destination branch, maintaining change history and permissions.
- Branch Renaming: Rename any branch in a Gerrit project
- Change Migration: Automatically move all associated changes to the new branch
- Flexible Options: Choose to include or exclude closed changes
- Permission Control: Granular permission system using Gerrit capabilities
- Robust Error Handling: Comprehensive error reporting and recovery
- Multiple Interfaces: Both REST API and SSH command support
-
Build the plugin:
bazel build plugins/rename-branch
-
Copy the plugin jar to your Gerrit plugins directory:
cp bazel-bin/plugins/rename-branch/rename-branch.jar $GERRIT_SITE/plugins/
-
Restart Gerrit or reload plugins:
ssh -p 29418 [email protected] gerrit plugin reload rename-branch
Grant the renameBranch
capability to groups that should be able to rename branches:
- Go to the All-Projects access control
- Add the
renameBranch
capability to desired groups (typically Administrators and Project Owners)
Users also need:
- DELETE permission on the source branch
- CREATE permission on the destination branch
- ABANDON permission on changes (to move them)
curl -X POST \
-H "Content-Type: application/json" \
-d '{
"source_branch": "master",
"destination_branch": "main",
"message": "Renaming default branch"
}' \
'https://gerrit.example.com/a/projects/my-project/rename-branch~rename-branch'
ssh -p 29418 [email protected] gerrit rename-branch rename-branch my-project master main --message "Renaming default branch"
bazel build plugins/rename-branch
bazel test plugins/rename-branch:rename-branch_tests
java -jar google-java-format.jar --replace $(find plugins/rename-branch -name "*.java")
- Communication: Always notify team members before renaming branches
- Timing: Perform renames during low-activity periods
- Backup: Ensure you have proper backups before major operations
- Testing: Test on non-critical branches first
- Permissions: Set up proper permissions before deployment
- Cannot rename branches currently being used in active Git operations
- Large repositories may experience longer processing times
- Operations are not fully atomic (individual change moves can fail)
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Submit a pull request
Licensed under the Apache License, Version 2.0.