GitHub warehouse master branch to main branch migration guide

Time:2021-11-24

1 Overview

After October 1, 2020,GithubThe default branch of all new warehouses will be transferred frommasterChange tomainThis leads to some old warehouse main branchesmaster, the main branch of the new warehouse ismainThis sometimes brings some trouble, so here is a scheme to replace the old warehousemasterBranch migration tomainBranch.

2 specific steps

Four steps:

  • Clone original warehouse
  • Create and pushmainbranch
  • Modify default branch
  • deletemasterbranch

2.1 cloning

First, clone a copy of the original warehouse to operate locally:

git clone xxxxxxx.git

2.2 create and pushmain

Create and switch tomain

git checkout -b main

Pushmain

git push origin main

2.3 modify default branch

This step requiresGithubEnter the warehouse settings and click the branch option:

GitHub warehouse master branch to main branch migration guide

Change the default branch tomain, and click the on the rightUpdate, clickUpdateThere will be a prompt after that, which may affectPRAnd cloning:

GitHub warehouse master branch to main branch migration guide

After confirming the modification, you can see that the default branch has been modified tomain

GitHub warehouse master branch to main branch migration guide

GitHub warehouse master branch to main branch migration guide

2.4 deletionmaster

Delete localmaster

git branch -d master

Delete remotemaster

git push origin :master

In this way, even if you successfully migrate tomainIt’s branching.

2.5 testing

Submit after making some modifications in the warehouse:

git add -A 
git commit -m "test main branch"
git push origin main

Can seeGithubThere will be corresponding updates on.