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.
Step by Step
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.
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
Checking the status, and confirming name
Let´s change the Local name
Checking status again shows locally the name is main and origin is master.
Let´s push main to origin (Github)
So now my local branch is main and updates against origin/main
How does it look in github now?
Still master, but now I have 2 branches, let´s change default branch to our new main.
Now my branch is main, but I still have 2 branches.
So, I am verifying that I have no changes to commit and hit delete.
There, now I only have a main branch.
2 Commands and 6 clicks later the change is done, and I only have main branch left.
One thought on “Renaming my GitHub master branch to main – the IT Pro guide!”