Skip to content

Instantly share code, notes, and snippets.

@josephg
Created January 31, 2023 22:36
Show Gist options
  • Save josephg/ba9dd30f8852ca9d455c363c65154075 to your computer and use it in GitHub Desktop.
Save josephg/ba9dd30f8852ca9d455c363c65154075 to your computer and use it in GitHub Desktop.
git push without bare
~/temp $ mkdir a
~/temp $ cd a
~/temp/a $ git init
Initialized empty Git repository in /home/seph/temp/a/.git/
~/temp/a:master ✓ $ cat > foo
asdf
~/temp/a:master ✓ $ git add foo
~/temp/a:master ✗ $ git commit -m 'initial import'
[master (root-commit) 7fe725a] initial import
1 file changed, 1 insertion(+)
create mode 100644 foo
~/temp/a:master ✓ $ cd ..
~/temp $ mkdir b
~/temp $ cd b
~/temp/b $ git init
Initialized empty Git repository in /home/seph/temp/b/.git/
~/temp/b:master ✓ $ cd ../a
~/temp/a:master ✓ $ git remote add backup ../b
~/temp/a:master ✓ $ git push backup
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 212 bytes | 212.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0), pack-reused 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 ../b
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '../b'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment