修改git init默认分支,master改为main

分支默认为main,从git 2.28版本开始支持,确保本地git版本大于等于2.28

一、查看或升级本地git版本

1、通过brew安装的git,或升级git

$ brew install git

$ brew upgrade git
Warning: git 2.29.2 already installed
2、查看git版本

发现与brew安装的Git没有关联,关联的是Mac默认的Git

$ git --version
git version 2.23.0
3、将git关联到brew安装的Git
$ brew link git --overwrite
Linking /usr/local/Cellar/git/2.29.2... 209 symlinks created
4、再次查看本地git版本
$ git --version
git version 2.29.2

二、配置

1、查看本地的默认分支配置

$ cat /Users/yuanzhiying/.gitconfig

$ cat /Users/yuanzhiying/.gitconfig
[filter "lfs"]
    clean = git-lfs clean -- %f
    smudge = git-lfs smudge -- %f
    process = git-lfs filter-process
    required = true
[user]
    name = yuanzhiying
    email = *********@qq.com
2、设置maingit init默认分支

$ git config --global init.defaultBranch main

3、再次查看本地配置
$ cat /Users/yuanzhiying/.gitconfig
[filter "lfs"]
    clean = git-lfs clean -- %f
    smudge = git-lfs smudge -- %f
    process = git-lfs filter-process
    required = true
[user]
    name = yuanzhiying
    email = ********@qq.com
[init]
    defaultBranch = main
4、验证
# yuanzhiying @ yingiMac in ~/test [12:18:54]
$ git init
已初始化空的 Git 仓库于 /Users/yuanzhiying/test/.git/

# yuanzhiying @ yingiMac in ~/test on git:main x [12:18:57]

你可能感兴趣的:(修改git init默认分支,master改为main)