How to change branch name

Hello, how can I change the name of a branch on a tree and than save the tree?

tree->GetBranch("old_name")->SetNameTitle("new_name", "new_name");
tree->Write()

doesn’t work: when I try to open the file

Error in <TFile::ReadBuffer>: error reading all requested bytes from file nupla_marc.root, got 0 of 26228

Hi,

Changing the name of a branch is currently not supported. You can either use an alias (See TTree::SetAlias) to be able to use the new name to refer to the old branch name or you will need to clone/copy the TTree.

Cheers,
Philippe.