繁体   English   中英

如何在Git中的裸存储库中创建分支

[英]How to create a branch in a bare repository in Git

我目前有一个简单的回购,作为我的团队的核心回购。 裸仓库目前只有一个分支“主”。 如何在裸仓库上创建更多分支?

通常,您不直接在裸存储库中创建分支,但是您将分支从一个工作存储库推送到裸存储库

git push origin myBranch

更新:值得一提

就像Paul Pladijs在评论中提到的那样

git push origin localBranchName:remoteBranchName

您将本地分支推送(并创建,如果不存在)到具有不同分支名称的本地分支,即本地分支。 并使其完整

git push origin :remoteBranchName

你删除了一个远程分支。

git update-ref refs/heads/new_branch refs/heads/master

在那个裸存储库中,如果您可以直接访问它。 您可以在最后一个参数中提供任何引用(例如标记)或提交。

以下是测试脚本:

$ mkdir non-bare-orig

$ cd non-bare-orig/

$ git init
Initialized empty Git repository in D:/Temp/bare-branch/non-bare-orig/.git/

$ touch file1

$ git add --all && git commit -m"Initial commit"
[master (root-commit) 9c33a5a] Initial commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 file1

$ touch file2

$ git add --all && git commit -m"Second commit"
[master 1f5673a] Second commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 file2

$ git tag some_tag

$ touch file3

$ git add --all && git commit -m"Third commit"
[master 5bed6e7] Third commit
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 file3

$ cd ../

$ git clone --bare non-bare-orig bare-clone
Cloning into bare repository 'bare-clone'...
done.

$ cd bare-clone/

$ git update-ref refs/heads/branch1 refs/heads/master

$ git update-ref refs/heads/branch2 some_tag

$ git update-ref refs/heads/branch3 9c33a5a

$ git branch -vv
  branch1 5bed6e7 Third commit
  branch2 1f5673a Second commit
  branch3 9c33a5a Initial commit
* master  5bed6e7 Third commit

创建一个名为branchname的新分支(本地)

git branch branchname

然后将它与远程存储库同步,如GitHub(如果适用)

git push origin branchname

并将其用于开发/使分支成为活动分支

git checkout branchname

暂无
暂无

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

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