我目前有一个裸仓库,用作我的团队的中央仓库。该裸仓库目前只有一个名为 "master" 的分支。如何在裸仓库上创建更多分支?
通常情况下,您不会直接在裸仓库中创建分支,而是从工作仓库将分支推送到裸仓库。
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
git branch branchname
接下来,如果适用的话,将其与远程仓库(如GitHub)同步。
git push origin branchname
使用它进行开发/将该分支设为活动分支
git checkout branchname
git push origin localBranchName:remoteBranchName
- Paul Pladijs