Selbi
Selbi

Reputation: 833

Retroactively rename branch?

About a week ago I started to play around in a new feature branch of my project. I named that branch "uploadtest" just as a way to find out how stuff works before I really do it.

Turns out, the uploading feature I was trying to implement was so simple that I've decided to simply finish work on that. Once I was done I merged the branch back into my "develop" branch. However, now looking at the commit history is a little weird, because the already merged branch makes it seem like a test, when in reality something like "uploadimpl" would be way clearer.

For my one-man project it's obviously not a problem, but if I were to do this in a team project, well, confusion would go through the roofs. Therefore, are there methods to retroactively rename a (merged) branch?

Upvotes: 1

Views: 3568

Answers (1)

Kevin Burdett
Kevin Burdett

Reputation: 2982

Renaming a branch is trivial, see How do I rename a local Git branch?

However, I think the issue you are referring to is the commit message, not the branch name. Once merged, the actual name of the branch is unimportant. In fact, you can simply delete it. However, the name of the branch is typically included in the merge's commit message. It sounds like you want to edit the history to change the name of the branch on the merge's commit message. This is possible, but re-writing history can be dangerous, especially in a team scenario.

If you have not pushed the merged changes to the remote repository then you can still accomplish this. Check out this question for some options: How to modify existing, unpushed commits?

If you have pushed these changes, then you are in dangerous territory. My general guidance is simply don't do this. Just let it go... But if you must, then check this out: Changing git commit message after push (given that no one pulled from remote)

Upvotes: 4

Related Questions