Dots to split versions when appropriate - Many open source projects use this convention to keep older versions of code.Use bars for subdivisions into a larger scope.There is common a practice of keeping the "master" branch always with the code in production, while using a "dev" branch where we mix all the code from other intermediate branches to test everything before we go into production.īut, besides we can't use spaces and some special characters, there are no definitive conventions for branch naming where we can say "this is wrong" and "this is right", but some good practices are recommended: And in order not to be ashamed of sending a pull request, I always try to follow a certain logic. Alternatively, you can use a single command. Rename the branch by entering the command: git branch -m new-name. You should receive confirmation that the branch is checked out. It's normal to have this doubt when naming a branch. Enter the name of the branch you want to change in your command-line interface: git checkout old-branch. What about the right way?īy the title of this article, I mean how to name a branch in the most correct manner according to common conventions and practices.Ī convention, in practice, is an agreement with your team and yourself. Both your local and remote branch have been renamed. The following command sends the renamed branch to the remote repository git push -set-upstream origin new-name Note: Replace "old-name" below with the old name of your branch to remove it. Without -f, git branch refuses to change an existing branch. Make sure you have the latest version of the remote branch in your local repository so you can push it right away. Warning: The method below excludes the remote branch. Unfortunately, there is no command that changes the name of the remote branch directly in Github, Bitbucket, etc., but we can remove and resend the branch with the desired name.įirst, we must change the name of our local branch as explained above: git branch -m "new-name" Just be careful not to use -M and overwrite another important branch by mistake. According to the documentation ( git branch -h), this parameter changes the name, even if it already exists. To do this, you should use git branch -M with the capital M. In some cases, you may want to change only the capitalization of some letter. If you want to change the name of another branch, while in the master, for example, use: git branch -m "old-name" "new-name" If you are already in the branch you want to change the name, use: git branch -m "new-name" Simple, right? But there are other things to learn about renaming a branch. So how do I rename a branch? According to the documentation, to rename a local branch in git there's only one command: git branch -m "new-name". From time to time I usually create a branch and then start messing with the code, and then I realize that what I'm doing has nothing to do with the name of that branch.
1 Comment
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |