Renaming my GitHub master branch to main – the IT Pro guide!

[ad_1]

As an “IT Pro”, manipulating my branches in GitHub does not really come as easy as it does for a Developer.

So here I document my steps as I guess this will be reoccurring for me going forward, my day to day work is in VSCode and doing commits and pull requests is part of it. Have not logged in to a server in a very long time and I am still doing “IT Pro” work.

There are many guides to this, but I figured there are more people are in my shoes, git commands and understanding for it is not a superpower we possess.
If you wonder, why change the name? read this post from Scott.

So I have this repo where I collect some scripts, snippet etc, will use this as the example.

The branch name is master, I want to change it to main.

RenameGithub1

I am following these two commands, basically I am renaming my local branch and pushing it so I get a new branch in GitHub.

git branch -m old_branch new_branch  # Rename branch locally
git push origin -u new_branch # Push the new branch, set local branch to track the new remote

So for my branch the commands would be

git branch -m master main  # Rename branch locally
git push -u origin main # Push the new branch, set local branch to track the new remote

First, I ensure I am in the correct local location.

For this repo it is

RenameGithub2

Checking the status, and confirming name

RenameGithub3

Let´s change the Local name

RenameGithub4

Checking status again shows locally the name is main and origin is master.

RenameGithub5

Let´s push main to origin (Github)

RenameGithub6

So now my local branch is main and updates against origin/main

RenameGithub7

How does it look in github now?

RenameGithub8

Still master, but now I have 2 branches, let´s change default branch to our new main.

RenameGithub9
RenameGithub10
RenameGithub11

Now my branch is main, but I still have 2 branches.

RenameGithub13

So, I am verifying that I have no changes to commit and hit delete.

RenameGithub14

There, now I only have  a main branch.

RenameGithub15

2 Commands and 6 clicks later the change is done, and I only have main branch left.

[ad_2]

Share this content:

I am a passionate blogger with extensive experience in web design. As a seasoned YouTube SEO expert, I have helped numerous creators optimize their content for maximum visibility.

Leave a Comment