It is well past time for your project to get rid of noninclusive terminology in your git branches! Code is for EVERYONE, so in the interest of making our language serve everyone equally, here is instructions for how to do it.
Starting A New Repo
The process is as follows:
- Create to your starting directory.
- Initialize the repository.
- Create a new “main” branch. I prefer main, trunk or root.
- Create a new file in the repo. Start with the .gitignore file.
- Add that file.
- Commit that change.
$ mkdir demo.branchinit
$ cd demo.branchinit
$ git init
Initialized empty Git repository in {Your Directory}
$ git checkout -b "main"
Switched to a new branch 'main'
$ touch .gitignore
$ git add .
$ git commit -am "First commit."
[main (root-commit) {hash}] First commit
1 file changed, 0 insertions(+), 0 deletions(-)
create mode {something} .gitignore
$ git branch
* main
Voila! The repo is now rooted off of your main branch, and the word master has nothing to do with it.
Changing an Existing Repo
An existing repo also easy to change, even if you have a remote source setup.
The process follows:
- Go to your existing master branch.
- Create a new ‘main’ branch, from that master branch.
- Drop the master branch.
- Push your new main branch to your remote.
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'
$ git checkout -b "main"
Switched to a new branch 'main'
$ git branch -d master
Deleted branch master (was {a hash})
$ git push origin main
Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
remote:
remote: Create a pull request for 'main' on GitHub by visiting:
remote: https://github.com/myorg/myProject/pull/new/main
remote:
To https://github.com/myorg/myProject
* [new branch] main -> main
Now you just need to reset the default branch in your remote.
- Navigate to your remote git source. I use my web browser for this.
- Update the default branch to your new ‘main’ branch.
- In GitHub,
- Go to your repo, click Settings
- Then Branches on the left.
- Select main in the Default Branch box, and click Update.
- Then click through the confirmation.
- In Azure DevOps Services
- Go to your repo, then Braches.
- Locate the main branch, and then click the 3 dots at the end of the row.
- Click ‘Set as default.’
- In GitHub,
Finally, clean up your local repo’s remote branches.
- While still in your main branch, reset the head on your remote.
- Delete the master branch!
$ git remote set-head origin -a
origin/HEAD set to main
$ git branch -d master
Deleted branch master (was {a hash})
Alright, you still have some work to do, but your local repo is nice and clean. You’ll still have to clean up your remote, but you can do so just like you would with any other branch delete.
Thanks for doing your part to make everything more inclusive! #blacklivesmatter
Per this article, https://www.zdnet.com/article/github-to-replace-master-with-alternative-term-to-avoid-slavery-references/ Github will be doing this for new repos! Great progress!
LikeLike