C
C#2y ago
langelescu

✅ How to "rename" Git remote branch?

On <remote> I have a Product/develop branch which I want renamed to Product/x_develop. Then I want to take the Product/y_develop, also on <remote> and rename to Product/develop. Both branches will continue to be in used. Product/develop will host the future development while 'Product/x_develop' will only be used for service packs. x/develop has service pack branches x.y, x.z, etc. What's the best way to go about this without breaking anything?
8 Replies
Sarco
Sarco2y ago
# Checkout x/develop branch
git checkout x/develop

# Create a new branch named Product/x_develop based on the x/develop branch
git checkout -b Product/x_develop

# Push the new branch to the remote repository
git push -u origin Product/x_develop

# Rename the y_develop branch to develop
git branch -m Product/y_develop Product/develop

# Push the renamed branch to the remote repository
git push origin :refs/heads/y_develop
git push -u origin Product/develop

# Rename the service pack branches
git branch -m x.y Product/x_develop.y
git branch -m x.z Product/x_develop.z

# Push the renamed service pack branches to the remote repository
git push -u origin Product/x_develop.y
git push -u origin Product/x_develop.z
# Checkout x/develop branch
git checkout x/develop

# Create a new branch named Product/x_develop based on the x/develop branch
git checkout -b Product/x_develop

# Push the new branch to the remote repository
git push -u origin Product/x_develop

# Rename the y_develop branch to develop
git branch -m Product/y_develop Product/develop

# Push the renamed branch to the remote repository
git push origin :refs/heads/y_develop
git push -u origin Product/develop

# Rename the service pack branches
git branch -m x.y Product/x_develop.y
git branch -m x.z Product/x_develop.z

# Push the renamed service pack branches to the remote repository
git push -u origin Product/x_develop.y
git push -u origin Product/x_develop.z
Btw this is a "breaking" change so you should probably tell other people about this if you're not the only one working on the repo I don't think it's possible to do this without "breaking" anything
langelescu
langelescuOP2y ago
I apologize, I've messed up the description in a fundamental way (perhaps). I've updated the name of the first branch from 'x/Develop' to 'Product/develop'. The takeaway is that I want the new branch to take the name of the old branch. And the old branch put away for just service packs. I don't want to lose data. I do expect this will require notifications and reconfiguraitons for the developers affected, but I don't want to get into some sort of irrecoverable data situation.
Sarco
Sarco2y ago
I think you can just make a new branch and keep the old and put up a note you're going to change the branch name and give time for other people to prepare their PR's
langelescu
langelescuOP2y ago
And I want the service packs that were branched off what was 'Product/develop' now to point to 'Product /x_develop', the new name for the old branch. Are the old service pack branches going to 'just work' with respect to the new 'Product/x_develop' branch? But I do not want to rename the service pack branches. Those names are set. I just want to preserve somehow the parenting relationship But not sure if I need to redo it manually, or it will just track the commit nodes, and essentially just work despite the renaming.
Sarco
Sarco2y ago
I think they should preserve "the relationship" with the service pack 🤔
langelescu
langelescuOP2y ago
So in theory, one would be able to take a service pack branch, let's say SP (originally branched off 'Product/develop') and merge it back into 'Product/x_develop'
Mayor McCheese
Branches are pointers to commits, so it's about what commits are in which path on the graph, if you've squashed a bunch of commits to long lived branches you're going to have a bad time, with lots of potential conflicts, some of it depends on your practices in git
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server