# Unable to push to local bare repository

2 messages from 2021-01-20 to 2021-01-21. Participants: Rich Davis, asymptosis.
Thread: https://gitlist.dev/t/55020

## Rich Davis, 2021-01-20 21:58

Subject: Unable to push to local bare repository
Message-ID: <8f1df022-0e0e-2451-b32d-2d9918604ea1@gmail.com>
URL: https://gitlist.dev/e/8f1df022-0e0e-2451-b32d-2d9918604ea1%40gmail.com

```
Hello GIT Community,

I have a question concerning initialization of bare repositories on a
local system; what am I overlooking?

I am attempting to init a bare repository locally, then clone the bare
repository to add files, then commit and push the content back:

========== Start Example ==========

$ git init barerepo
Initialized empty Git repository in /tmp/am_i_crazy/barerepo/.git/
$ git clone --dissociate --no-hardlinks --no-local barerepo clonerepo
Cloning into 'clonerepo'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.
$ cd clonerepo/
$ echo "This is a test file created on $(date +%Y-%m-%d_%H:%M:%S)" >
test.txt
$ git add test.txt
$ git commit --message "Initial commit."
[master (root-commit) da5f435] Initial commit.
 1 file changed, 1 insertion(+)
 create mode 100644 test.txt
$ git push origin master
Counting objects: 3, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 914 bytes | 0 bytes/s, done.
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: error: is denied, because it will make the index and work tree
inconsistent
remote: error: with what you pushed, and will require 'git reset --hard'
to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration
variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow
pushing into
remote: error: its current branch; however, this is not recommended
unless you
remote: error: arranged to update its work tree to match what you pushed
in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default
behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to
'refuse'.
To /tmp/am_i_crazy/barerepo
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '/tmp/am_i_crazy/barerepo'
$ git version
git version 2.7.4
========== End Example ==========

From what I was able to find in the man page, there is an optimization
that takes place locally when the upstream repository is on the same
system / file system; I have attempted to disable that, but I am unsure
if that is what is causing the problem. I am also curious as to why the
error message refers to the upstream repository as "non-bare"?


Thank you for your time,

Rich Davis*
*



```

## asymptosis, 2021-01-20 23:59

Subject: Re: Unable to push to local bare repository
Message-ID: <YAjD+Gtm1QwdwXCq@sleipnir.acausal.realm>
URL: https://gitlist.dev/e/YAjD%2BGtm1QwdwXCq%40sleipnir.acausal.realm
In-Reply-To: <8f1df022-0e0e-2451-b32d-2d9918604ea1@gmail.com>

```
Hi Rich,

>$ git init barerepo
>Initialized empty Git repository in /tmp/am_i_crazy/barerepo/.git/

This looks like your problem: without passing the --bare flag, it's not a bare repo. It even says it's initialized under barerepo/.git instead of barerepo.

Compare with the result of passing --bare:

ˋˋˋ
testuser /tmp $ git init --bare barerepo
Initialized empty Git repository in /tmp/barerepo/

testuser /tmp $ git clone --dissociate --no-hardlinks --no-local barerepo clonerepo
Cloning into 'clonerepo'...
warning: You appear to have cloned an empty repository.

testuser /tmp $ cd clonerepo/

testuser /tmp/clonerepo $ printf "This is a test file created on %s\n" "$(date +%Y-%m-%dT%H:%M:%S)" | tee test.txt
This is a test file created on 2021-01-21T10:55:35

testuser /tmp/clonerepo $ git add test.txt

testuser /tmp/clonerepo $ git commit -m "Initial commit"
[master (root-commit) b71804b] Initial commit
  1 file changed, 1 insertion(+)
  create mode 100644 test.txt

testuser /tmp/clonerepo $ git push origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 253 bytes | 253.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
To /tmp/barerepo
  * [new branch]      master -> master
ˋˋˋ

Hope this helps.

```
