Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mercurial: Can I rename a branch?

People also ask

Can a branch be renamed?

The git branch command lets you rename a branch. To rename a branch, run git branch -m <old> <new>. “old” is the name of the branch you want to rename and “new” is the new name for the branch.

Can you change the name of a remote branch?

Rename a Remote Git BranchThere isn't a way to directly rename a Git branch in a remote repository. You will need to delete the old branch name, then push a branch with the correct name to the remote repository. The output confirms that the branch was deleted.


Update to the stiging branch and create a new branch off of it. Then close the old branch.

In summary:

hg update stiging
hg branch staging
hg commit -m"Changing stiging branch to staging."
hg update stiging
hg commit --close-branch -m"This was a typo; use staging instead."
hg push --new-branch

For future readers: With the rebase extension, you can make a new branch with the same parent as stiging and move the entire branch history to it, like this:

hg update -r "parents(min(branch('stiging')))"
hg branch staging
hg commit
hg rebase --source "min(branch('stiging'))" --dest staging

This assumes that stiging has only one parent. Of course you can just use explicit revision numbers instead.

Note 1: If branch stiging includes merges with other branches, I think that this will preserve them, as long as staging and stiging have the same parent. But I'd certainly double-check.

Note 2: Since this edits the history, the old branch won't simply disappear from cloned repositories (see the rebase documentation). Unless everyone can clone anew, it might not be a very practical solution for a large group.

Note3/Edit (courtesy of @JasonRCoombs): Now that phases are standard in mercurial, rebase will refuse to modify changesets that have already been pushed. Either fool it by changing the phase back to draft (with hg phases), or let the old branch stay where it is, and just make a properly named copy (e.g., with `hg rebase --keep').


Make a new branch called "staging" and forget the other...


If you have changesets on it, then you'll have to use the convert extension with a branchmap to rename it. Everyone will then have to clone the new repo or strip off the old branch.


This modifies the history and is only for advanced Mercurial users. Don't do this if you don't know what that means.

If stiging is local only, you can change it to staging with a combination of graft and strip. Start by updating to the ancestor changeset where stiging had diverged. Create the staging branch and graft each commit from stiging to staging. Staging should now be a copy of stiging. Lastly, destroy stiging by stripping its first commit.

hg update {SHA-1 of the ancestor changeset}
hg branch staging
hg graft {first changeset in stiging} ... {stiging head-1} {stiging head}
hg strip {first changeset in stiging}
hg push --new-branch