DEV Community

Discussion on: Replacing master in git

Collapse
 
mburszley profile image
Maximilian Burszley • Edited

The Git Development Community is working to at least make the name of the main branch easily configurable

What's wrong with it now?

mkdir /tmp/git-init && cd $_
git init && git checkout -b main
git commit -m init --allow-empty
git branch -a
git log --oneline
Collapse
 
jnareb profile image
Jakub Narębski

As far as I remember, changing the default branch would be able to be done with command line parameter or a configuration variable

git init --default-branch=main

or

git config branch.default main
# ...
git init
Collapse
 
shaunagordon profile image
Shauna Gordon

Please tell me you're being facetious...

Thread Thread
 
mburszley profile image
Maximilian Burszley

Why would I be? It's as easy as specifying the branch name in your checkout command to change what your default is.

Thread Thread
 
shaunagordon profile image
Shauna Gordon

Because you asked what was wrong with a 7-step init process, in response to someone mentioning that the git developers are working on making it a configuration option.

Thread Thread
 
mburszley profile image
Maximilian Burszley

It's not a seven-step process, though, that was just a complete example for illustration. It's as simple as:

git init
git checkout -b main
Thread Thread
 
shaunagordon profile image
Shauna Gordon

Or, we can just do

git config --global init.defaultBranch main

once, and never have to worry about it again.

We also don't have to worry about alias syntax, which is terminal-type-dependent, and can include it in provisioning/dotfiles repos and it works regardless of the person's system. :)

Thread Thread
 
jnareb profile image
Jakub Narębski

This option was, as far as I know, not available at the time of writing the blog post in question, and possibly also when I was writing my comment.

Thread Thread
 
shaunagordon profile image
Shauna Gordon

It wasn't available yet (though it was already in the pipeline). I was responding to Max, whose response suggested that the addition wasn't necessary and the then-current workflow was sufficient.

Even if the latest release (with this config option) hadn't been out when I responded with the config, I still would have argued in favor of having it as a config option, with the same arguments of being able to set it once and not have to worry about terminal aliases, etc.

Some comments have been hidden by the post's author - find out more