How to create a branch in a bare repository in Git

后端 未结 3 1917
眼角桃花
眼角桃花 2021-02-04 00:55

I current have a bare repo thats acts as a central repo for my team. The bare repo currently only have a branch \"master\". How can I create more branches on the bare repo?

3条回答
  •  情歌与酒
    2021-02-04 01:23

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

    In that bare repository if you have direct access to it. You may supply any reference (a tag for instance) or a commit in the last argument.

    Below is a test script:

    $ 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
    

提交回复
热议问题