Git:本地跟踪,添加新分支?

时间:2015-11-18 16:19:48

标签: git github

我正在尝试清理我的git存储库和

  1. 创建一个镜像我的生产(主)分支的新分支。
  2. 删除任何不必要的分支,远程或本地。
  3. 让我的本地分支机构本地跟踪分支机构(如果我需要这样做,可以获益吗?)
  4. 我的工作流程的每个阶段都有一个分支,即本地和分支的一个分支。 dev(dev),1个用于分段(分段)的分支,以及1个用于生产(生产)的分支。本地和开发人员可以共享相同的工作分支,但可以分别进行分段和生产。
  5. 从命令行可以看到我的环境。

    $ git remote
    dev
    origin
    production
    staging
    
    $ git branch -r
    dev/dev
    origin/HEAD -> origin/master
    origin/dev
    origin/master
    production/master
    wpengine-findcra/master
    
    $ git branch -vv
    dev                   xxxxxxx <comment>
    *master               xxxxxxx [origin/master] <comment>
    production/staging    xxxxxxx [remotes/production/master] <comment>
    staging/master        xxxxxxx <comment>
    

    我有4个工作地点。代码从1流到4.

    1. 我的本地机器
    2. 开发服务器
    3. 登台服务器
    4. 生产服务器
    5. 我想专门为登台服务器添加一个新分支,现在我想让它镜像生产(主)分支。但我遇到了错误,我不知道该怎么做。

      $ git checkout master
      $ git branch staging
      error: there are still refs under 'refs/heads/staging'
      fatal: Failed to lock ref for update: Is a directory
      

      我的代码在origin / master和dev / dev。

      下是最新的

1 个答案:

答案 0 :(得分:10)

If you have a branch with a name that contains a slash, git will create (in .git/refs/heads) a directory named like the name of your branch until the slash. In that directory it will place the refs for the branch itself. So the directory .git/refs/heads/staging/ exists and contains a file "master" due to your branch staging/master.

When you try to create the branch "staging", git will try to create the file .git/refs/heads/staging. As this already exists but is a directory, this will fail. Thus you cannot have two branches with these names in your repository.

In more recent versions of git the error message will look like this:

fatal: cannot lock ref 'refs/heads/staging': 'refs/heads/staging/master' exists; cannot create 'refs/heads/staging'