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?
An empty repository cannot have a branch, branches are pointers to commits. So you first have to commit something in the empty repository before the branch can be created. You can either commit the code from the other repository, or just an empty file, create your branch and then commit the code.
Using a Bare Repository A bare repository is linked with a local repository, hence the files in . git of local repo should match with the files in the bare repo. First, create a bare repository (See section for the code snippet).
Usually you don't create branches directly in the bare repository, but you push branches from one work repository to the bare
git push origin myBranch
Update: Worth to mention
Like Paul Pladijs mentioned in the comments with
git push origin localBranchName:remoteBranchName
you push (and create, if not exists) your local branch to the remote with a different branch name, that your local one. And to make it complete with
git push origin :remoteBranchName
you delete a remote branch.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With