0

I'm about to rename a branch locally and remotely using the advice provided in the following answer and many more like it:

https://stackoverflow.com/a/30590238/419

The current name of the branch is coredev and the new name of the branch will be newcoredev.

This is fine for me, it works. But most of these examples appear to assume you're not working with a team with in-flight open feature or bugfix branches created from coredev on their own machines.

Is there something extra I need to do or be concerned about to ensure that after renaming coredev to newcoredev (with its open branches) that won't create a world of pain for my colleagues?

SoAnon
  • 1
  • 1
    Does this answer your question? [Rename master branch for both local and remote Git repositories](https://stackoverflow.com/questions/1526794/rename-master-branch-for-both-local-and-remote-git-repositories). See Aristotle's answer and the comments below it: https://stackoverflow.com/a/3790682/8910547 – Inigo Jul 07 '21 at 01:05
  • 1
    Remember git branches are merely pointers at commits. So you renaming `coredev` to `newcoredev` has zero impact on branches created from `coredev`. To another user pulling from the central repo, the only thing they need to do is create a new branch tracking `origin/newcoredev`. They don't even have to delete their local `coredev` if they don't want to. – jingx Jul 07 '21 at 03:51

1 Answers1

0

I'm not quite sure this is a duplicate, but if it's not, it's not really a programming question. So, I'm going to add this answer here, but it's at least a little bit off topic.

As jingx noted in a comment, Git does not really care about branch names at all. It just uses them to find commits. You can change the spelling of the name as little or as much as you like, e.g., feature/behavior can become feature/behavior or even jean-baptiste-emanuel-zorg, and it all makes no difference at all to Git itself.

There are two places where it does matter, though:

  1. Each branch, in each repository, can have an upstream set. The upstream of a branch is simply another string, but it's often the string corresponding to the remote-tracking name in your repository, which your Git creates or updates based on the branch name in some other repository.

    When the remote repository Git drops branch name B1 in favor of new name B2, your Git will—let's assume the remote is called origin for concreteness here—create your origin/B2 on your next git fetch. If you have enabled --prune (fetch.prune = true) or use it explicitly, your Git will also delete your origin/B1; if not, it won't. Either way, the upstream setting of your own branch—let's say you've called your branch zorg and set its upstream to origin/B1—is now "wrong" in some way as you should change it to origin/B2.

  2. Humans assign significance to branch names. feature/behavior, whether spelled in American or British style, is neutral; zorg implies that the branch is evil. If you're in favor (or favour) of evil, you might want to rename your local branch.

The course of action required for both of these items is the same: tell your co-workers / collaborators / others that you are renaming the branch. They can take any action they need to take, based on this.

torek
  • 448,244
  • 59
  • 642
  • 775
  • I think git is well within the scope of SO with 134k questions, and it's a developer tool. This is my anon account (to stay out of my employer's radar) and know the SO rules fairly well, I'm a 12 yr veteran of the site :). Thanks for the answer though. I've set up a sandbox to do a dry run both as me as the branch renamer and as a simulated colleague. Will let you know how I get on. – SoAnon Jul 07 '21 at 22:45
  • What I meant is: to the extent that it's on topic, it is a duplicate, as the other links commenters provided cover the mechanics of branch renaming. The rest is more software-engineering... – torek Jul 08 '21 at 01:17