How to create master branch in remote repositories?

W William June 4, 2020

I encounter an issue when I create a bare repository. Here is my step:

1. Create a folder named `Test` in a `C:\` as a remote repository
2. Create repository in sourcetree and select `C:\Test`
3. Input command `git init --bare` in terminal
4. Clone `C:\Test` to my local folder `D:\Test`

However, I can't see master branch in both `C:\Test` and `D:\Test`. How can I create a master branch? Thanks

PS: my `C:\Test` has hooks, info, objects, refs, config, description, HEAD. Do I need to check in them and make them as master branch?

1 answer

1 accepted

0 votes
Answer accepted
Sandesh Shetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 4, 2020

A bare repository is pretty much something you only push to and fetch from. You cannot do much directly "init": you cannot check stuff out, create references (branches, tags), run git status, etc.

If you want to create a new branch in a bare Git repository, you can push a branch from a clone to your bare repo:

cd cloned-repo

touch README.md

git add .

git commit -m "added readme"

git push origin master 

W William June 4, 2020

Thanks for your answer. But I tried this before. and I got this error. Does my procedure of setting up repo right?

Total 3 (delta 0), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: is denied, because it will make the index and work tree inconsistent
remote: with what you pushed, and will require 'git reset --hard' to match
remote: the work tree to HEAD.
remote:
remote: You can set the 'receive.denyCurrentBranch' configuration variable
remote: to 'ignore' or 'warn' in the remote repository to allow pushing into
remote: its current branch; however, this is not recommended unless you
remote: arranged to update its work tree to match what you pushed in some
remote: other way.
remote:
remote: To squelch this message and still keep the default behaviour, set
remote: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
To C:\Test
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'C:\Test'

Sandesh Shetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 4, 2020

@W William Try this and then push

git config --bool core.bare true

W William June 4, 2020

Thanks mate! It works!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events