This script makes the variable names clearer and adds a confirmation message at the end. You can easily change the branch names by modifying the variables at the top.
Created
April 17, 2025 03:48
-
-
Save iqiancheng/58f774dd97b07e00311808ea2eeda7d2 to your computer and use it in GitHub Desktop.
Git Rename Branch Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Define branch variables | |
OLD_BRANCH="qwen2_5_dpo" | |
NEW_BRANCH="qwen2_5_dpo_updated" | |
FINAL_BRANCH="qwen2_5_dpo" | |
# Switch to the updated branch | |
git checkout $NEW_BRANCH | |
# Delete old branch locally | |
git branch -D $OLD_BRANCH | |
# Rename current branch to final name | |
git branch -m $FINAL_BRANCH | |
# Push renamed branch to remote and set tracking | |
git push -u origin $FINAL_BRANCH | |
# Delete the old named branch on remote if it exists | |
git push origin --delete $NEW_BRANCH | |
echo "Branch rename complete: $NEW_BRANCH → $FINAL_BRANCH" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment