简体   繁体   中英

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?

  1. rename your local branch:

     git branch -m master main
  2. change the tracked branch

    git fetch -p origin git branch -u origin/main main
  3. change the main local branch

    git remote set-head origin -a
  4. optionally, remove the master branch, local and remotely:

     git branch -D master git push origin:master

Updates

  • added the -p parameter in step 2, thanks to @torek.
  • add the optional step to remove the master branch

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM