Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to create master branch in remote repositories?

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

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 

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'

@W William Try this and then push

git config --bool core.bare true

Thanks mate! It works!

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

Powering DevOps with Bitbucket Server & Data Center

Hi everyone, The Cloud team recently announced 12 new DevOps features that help developers ship better code, faster   ! While we’re all excited about the new improvements to Bitbucket ...

1,880 views 0 7
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you