Categories
Git

GitHub: Rename master branch to main and make it the default

To rename the master branch to main and make it the default branch in your GitHub repository, follow these steps:

  1. Clone the repository from GitHub:
    • Open your terminal or command prompt.
    • Navigate to the directory where you want to clone the repository.
    • Run the following command to clone the repository:
      git clone https://github.com/username/repository.git
      

      Replace username with your GitHub username and repository with the name of your repository.

  2. Navigate to the cloned repository:
    • Change your current directory to the cloned repository by running:
      cd repository
      

      Replace repository with the name of your repository.

  3. Rename the master branch to main locally:
    • Run the following command to rename the branch:
      git branch -m master main
      
  4. Push the main branch to GitHub:
    • Run the following command to push the renamed branch to GitHub:
      git push -u origin main
      
  5. Update the default branch on GitHub:
    • Go to your repository on GitHub.
    • Click on the "Settings" tab.
    • In the left sidebar, click on "Branches".
    • Under "Default branch", click on the "Change default branch" button.
    • In the dropdown menu, select "main" as the new default branch.
    • Click on "Update" to save the changes.
  6. Delete the master branch on GitHub (optional):
    • If you want to remove the master branch from your GitHub repository, you can do so by running the following command:
      git push origin --delete master
      

Leave a Reply

Your email address will not be published. Required fields are marked *