Unable to push to local bare repository

2 messages, 2 authors, 2021-01-21 · open the first message on its own page

Unable to push to local bare repository

From: Rich Davis <hidden>
Date: 2021-01-20 23:42:51

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*
*

Re: Unable to push to local bare repository

From: asymptosis <hidden>
Date: 2021-01-21 00:56:52

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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help