DEV Community

loading...
Cover image for How to migrate master branch to main in Github?

How to migrate master branch to main in Github?

Tham
Personal Mastery Coach | Lean Growth Strategist | API Evangelist | Chief Hustler @WorkRituals
・1 min read

Few months back, Github changed the default branch from master to main. Due to this change, most of the projects were forced migrate from master to main branch. Recently I faced this problem for one of my projects.

After multiple trials and errors, I successfully migrated my project to main branch. I would like to share the steps and it would help you when you face the similar problem in the future.

1: Connect local repo with your remote repo

git remote add origin <remote_github_url>
Enter fullscreen mode Exit fullscreen mode

2: Pull the main source code

git pull origin main
Enter fullscreen mode Exit fullscreen mode

3: Move the source from master to main branch

git branch -m master main
Enter fullscreen mode Exit fullscreen mode

4: Add and commit your changes

git add .
git commit -m "master branch changed to main"
Enter fullscreen mode Exit fullscreen mode

5: Set upstream and push changes to remote

git push --set-upstream origin main
Enter fullscreen mode Exit fullscreen mode

Now all your changes will be available in the remote main branch.

NOTE: Backup your source code before you do all these changes.

Discussion (0)