首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在Git中的裸存储库中创建分支

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

Stack Overflow用户
提问于 2011-12-05 15:33:16
回答 3查看 21.2K关注 0票数 24

我目前有一个简单的回购,作为我的团队的中央回购。裸回购目前只有一个分支"master“。如何在纯repo上创建更多分支?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2011-12-05 15:36:54

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

git push origin myBranch

更新:值得一提的是

就像Paul Pladijs在评论中提到的

git push origin localBranchName:remoteBranchName

您使用不同的分支名称将本地分支推送(如果不存在,则创建)到远程。为了使其完整,请使用

git push origin :remoteBranchName

您可以删除远程分支。

票数 22
EN

Stack Overflow用户

发布于 2015-10-30 17:47:28

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
票数 12
EN

Stack Overflow用户

发布于 2011-12-05 15:47:22

要在本地创建名为分支名称的新分支,请执行以下操作

git branch branchname

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

git push origin branchname

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

git checkout branchname
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8382212

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档