Skip to content

Instantly share code, notes, and snippets.

@iqiancheng
Created April 17, 2025 03:48
Show Gist options
  • Save iqiancheng/58f774dd97b07e00311808ea2eeda7d2 to your computer and use it in GitHub Desktop.
Save iqiancheng/58f774dd97b07e00311808ea2eeda7d2 to your computer and use it in GitHub Desktop.
Git Rename Branch Script

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.

#!/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