Home Git Repo: bare, or not bare

After deciding on where to locate my personal git repo, I hit a snag…

I went into a test folder, ran git init --bare, and got a bunch of files I was not totally expecting. Instead of having the files in a .git folder like a project, the repo dumps the contents into the current folder you’re in. This is a problem.

Output of `git init –bare`

My end goal is to have all of the files in the expected path: ~/Documents/Work/Organization/*. That way if I SSH into my server, I can still access them like normal. Then the other half is that I want to be able to use git locally and push/pull the file changes to/from the server.

I did some playing around with the test folder and found something interesting. If you have an existing repo, you can run git clone on the .git folder in that existing repo. You will get a copy of all the files! However, if you try and make a change locally and push it, you’ll get the following error message:

Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Writing objects: 100% (3/3), 265 bytes | 265.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 {remote}:/{path}/test
 ! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to '{remote}:/{path}/test'

Based on the error message, it looks like its complaining about pushing to a non-bare repo (what I just setup). By pushing a change to the repo, there would be a conflict between the working files, and what git thinks is the HEAD. In order to keep them in sync, I’d either need to reject the push or update the files.

I looked up a solution and found that if you run the following command on the remote repo, it will automatically update the files so the HEAD and working tree are in sync:

git config receive.denyCurrentBranch updateInstead