'How to change current branch in git from master to main
It is common to change main branches from the old pattern master to main. This can be easily done remotely (GitHub offers a graphical way to do it), but... what should be done with working copies?
Solution 1:[1]
rename your local branch:
git branch -m master mainchange the tracked branch
git fetch -p origin git branch -u origin/main mainchange the main local branch
git remote set-head origin -aoptionally, remove the master branch, local and remotely:
git branch -D master git push origin :master
Updates
- added the
-pparameter in step 2, thanks to @torek. - add the optional step to remove the master branch
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
