简体   繁体   English

删除私有服务器(不是GitHub)上的git master分支

[英]Delete git master branch on a private server (not GitHub)

I have a project hosted on my own personal git server (it is not on GitHub). 我有一个项目托管在我自己的个人git服务器上(它不在GitHub上)。 The master branch is a stale old cookie, and I don't need it anymore. master分支是陈旧的cookie,我不再需要它了。

A couple of months ago I created a 0.8/develop branch off of master and since then we've gone through 0.8/master , 0.9/develop , 0.9/master and we're currently on 1.0/develop . 几个月前,我创建了一个0.8/develop分支关闭的master ,从那时起,我们已经经历了0.8/master0.9/develop0.9/master ,我们现在是在1.0/develop I'd like to get rid of the master branch, mainly because it doesn't match the naming convention that we've established. 我想摆脱master分支,主要是因为它与我们建立的命名约定不符。 It's just a matter of housekeeping. 这只是家务管理的问题。

I found several related questions on SO, as well as a blog post, but they all seem to be specific to use of GitHub, and not my own private server: 我在SO上发现了几个相关的问题,以及博客文章,但它们似乎都特定于使用GitHub,而不是我自己的私人服务器:

These both specifically say something to the effect of: 这些都具体说明了以下内容:

You need to go to the main GitHub page for your forked repository, and click on the 'Settings' button. 您需要转到分叉存储库的主GitHub页面,然后单击“设置”按钮。

Of course, this is not an option as I'm not using GitHub. 当然,这不是一个选项,因为我没有使用GitHub。 I'm guessing that I can edit the contents of the config file in my bare repo to achieve the same results. 我猜我可以在我的裸仓库中编辑配置文件的内容以达到相同的效果。 Is that correct? 那是对的吗? The config file currently looks like this: 配置文件目前看起来像这样:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = true
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = false
        sharedRepository = group
[remote "origin"]
        url = file:///Library/WebServer/Documents/loupe
        fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
        remote = origin
        merge = refs/heads/master

I have two questions: 我有两个问题:

  1. Should I set my default repo to my current working branch ( 1.0/develop ), or the oldest branch that's left ( 0.8/develop )? 我应该将我的默认仓库设置为当前工作分支( 1.0/develop ),还是剩下最旧的分支( 0.8/develop )?
  2. What modifications do I need to make to the config file to set the default repo? 我需要对配置文件进行哪些修改才能设置默认仓库?

First decide which branch should be the default branch when the repository is cloned. 首先确定在克隆存储库时哪个分支应该是默认分支 I assume new_master for this example. 我假设这个例子是new_master

On one of the clients create the new_master branch on the remote repository, you may use anything for master instead, eg a commit or another branch name, or skip this step if you already have a suitable branch on the remote. 在其中一个客户端上创建远程存储库上的new_master分支,您可以使用任何东西代替master ,例如提交或其他分支名称,或者如果您已在远程new_master上有合适的分支,则跳过此步骤。

git push origin master:new_master

The next step can't be done from remote, so execute the command in your remote repository (eg using SSH): 下一步无法从远程执行,因此请在远程存储库中执行该命令(例如,使用SSH):

cd /path/to/my_git_repo
git symbolic-ref HEAD refs/heads/new_master

Alternatively, change the content of the HEAD file directly. 或者,直接更改HEAD文件的内容。

Back on the client: 回到客户端:

git fetch
git remote show origin

You should see that the HEAD points to new_master instead of master (or that HEAD is ambiguous if you set new_master to be master ). 您应该看到HEAD指向new_master而不是master (或者如果您将new_master设置为master ,则HEAD是不明确的)。 Now we can remove the old master: 现在我们可以删除旧的主人:

git push origin :master

Git shouldn't complain anymore about the deletion. Git不应再抱怨删除了。 Finally, set the local refs/remotes/origin/HEAD : 最后,设置本地refs/remotes/origin/HEAD

git remote set-head origin -a

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM