You now know how to git change branch name, how to rename a local git branch, and how to rename the git master branch to main using the git branch -m command. I normally keep all branch names lowercase to avoid causing confusing issues when trying to find a branch, and use hyphens to make the names readable. It’s also worth noting that branch names are case sensitive. Please note there is only 1 dash before the ‘m’ and 2 dashes before the ‘move’. git branch -set-upstream-toorigin/bract bract (note that the origin/ version of the name goes after the equal sign, with no space, in this format the branch name itself is optional and if you leave it out Git will assume 'the current branch name'). And -m and –move do exactly the same thing. Short version: use git branch -set-upstream-to to fix the upstream setting, e.g. What is the -m flag in this command? : git branch -m branch-name-now new-branch-name This is exactly the same as: git branch -move branch-name new-branch-name What are Git branch -m and –move … which renames the branch which is called branch-name to new-branch-name. The first line uses this generic command form: git branch -m branch-name new-branch-name The first line renames the local master branch to main, the second line pushes new main branch to the remote repo. If you want to rename your master branch to main then run this git command: git branch -m master main Some git systems still name the initial git branch master but it’s pretty common in other systems for the initial branch to be called main, which is my preference. You can see in the image above that I am still on main, there are still 3 other branches, but we now have a branch called new-branch-name instead of branch-name-now. ![]() Now use the git branch command to list your local branches again. This means ‘please rename the branch which is called branch-name-now to new-branch-name‘. Putting all of this together you can use this command to rename a local git branch : git branch -m branch-name-now new-branch-name You will also have to specify the name of the branch you want to rename and the name you want to rename it to. To rename a local git branch you need to use the git branch -m command ( official documentation is here). You can also see that there are 3 other branches, one of which is called branch-name-now. In the list you can see in the image above that we are currently on the main branch, as it’s highlighted in green and has an asterisk next to it. How to Git rename master branch to mainīefore we start renaming any branches get a list of your branches using the git branch command with no flags, as shown here:. ![]() ![]() Use git branch to see local branch names.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |