得之我幸 失之我命

when someone abandons you,it is him that gets loss because he lost someone who truly loves him but you just lost one who doesn’t love you.

修改远端 repo 的默认分支

搭建 Git 服务器

1
2
3
4
5
$ mkdir test.git  # 创建 Git 资源的存储目录 test.git
$ git init --bare test.git # 在 test.git 目录中初始化 Git 的基本配置信息
# 添加系统用户和用户组,如 test_git:test_git_grp
$ chown -R test_git:test_git_grp test.git # -R :递归,表示递归 test.git 中的所有文件归属到指定用户 test_git 上
$ git clone test_git@7.7.7.7:/home/test_git/test.git test

可是,这时候服务器 git 仓库中初始化的默认分支是 master,我想改成其他的要怎么操作?

当我在本地直接尝试删除其他分支一样去删除 origin/master 分支时,会报错,即便是我本地切换到其他分支,依然会报下面的错

1
2
3
4
5
6
7
8
9
10
11
12
remote: error: By default, deleting the current branch is denied, because the next
remote: 'git clone' won't result in any file checked out, causing confusion.
remote:
remote: You can set 'receive.denyDeleteCurrent' configuration variable to
remote: 'warn' or 'ignore' in the remote repository to allow deleting the
remote: current branch, with or without a warning message.
remote:
remote: To squelch this message, you can set it to 'refuse'.
remote: error: refusing to delete the current branch: refs/heads/master
To 7.7.7.7:/home/test_git/test.git
! [remote rejected] master (deletion of the current branch prohibited)
错误:无法推送一些引用到 '7.7.7.7:/home/test_git/test.git'

好在这是我自己的 git 服务器,我可以直接访问

1
2
$ cd test_git
$ git symbolic-ref HEAD refs/heads/main # 可以看到 HEAD 文件中的内容变成了 ref: refs/heads/main

在这之后,就可以在本地像删除一个普通分支一样去删除服务器的 master 了

be slow to promise and quick to perform.