About me: My name is Solène Rapenne, pronouns she/her. I like learning and sharing knowledge. Hobbies: '(BSD OpenBSD Qubes OS Lisp cmdline gaming security QubesOS internet-stuff). I love percent and lambda characters. OpenBSD developer solene@. No AI is involved in this blog.

Contact me: solene at dataswamp dot org or @solene@bsd.network (mastodon).

You can sponsor my work financially if you want to help me writing this blog and contributing to Free Software as my daily job.

Git push to non-bare repository

Written by Solène, on 17 May 2016.
Tags: #git #versioning #solved

Comments on Fediverse/Mastodon

Hello

You have a git repository where you work in, and you would like to work on a clone of it and push the data back to it ? You may encounter issues if your git repository isn’t a bare one. I have been facing this problem by using gitit, which works with a non-bare git repository.

What is a bare git repository ?

Here is how to create a bare repository and what it looks like.

$ git init --bare repo 
$ ls -a repo/
.            HEAD         config       hooks        objects
..           branches     description  info         refs

You can’t work in this, but this is the kind of repository that should be used to store/push/clone etc..

What is a non-bare git repository ?

Here is how to create a non-bare repository and what it looks like.

$ git init repo2
$ ls -a repo2
.    ..   .git

You may use this one for local use, but you may want to clone it later, and work with this repository and doing push/pull. That’s how gitit works, it has a folder “wikidata” that should be initiated as git, and it will works locally. But if you want to clone it on your computer, work on the documentation and then push your changes to gitit, you may get this error when pushing :

Problem when pushing

I cloned the repository, made changes, committed and now I want to push, but no…

Décompte des objets: 3, fait.
Écriture des objets: 100% (3/3), 232 bytes | 0 bytes/s, fait.
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'.
 ! [remote rejected] master -> master (branch is currently checked out)

git is unhappy, I can’t push

Solution

You can fix this “problem” by changing a config in the server repository with this command :

$ git config --local receive.denyCurrentBranch updateInstead

Now you should be able to push to your non-bare repository.

Source: Stack Overflowk link where I found the solution