7

I bought a personal dev box which I will use for deploying stuff I create on my laptop. I thought it would be a good idea to use Git for code management. The idea was that I will keep committing on my laptop and when needed, will push the changes to the remote dev box.

  1. I initialized a Git repo on the box and
  2. cloned it on my laptop.
  3. But After doing git push I get this error:

    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

I know that the remote repo was not bare.

I want to ask if the only way to go with my kind of setup is:

  1. Initialize a bare repo on Server
  2. Clone it on my laptop
  3. add new files to the local laptop repo and commit the files
  4. push to the remote dev box repo

Even this setup gives me errors:

No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
fatal: The remote end hung up unexpectedly

EDIT

I tried

git push origin master

Got this error:

error: unable to create directory for .git/refs/remotes/origin/master
error: Cannot lock the ref 'refs/remotes/origin/master'.

Oh dumb me... I think it is sudo as in

sudo make me intelligent

2 Answers2

10

The first message, as you said, was because the remote was not a bare repo.

The second message was because the bare repo you created had no branches to begin with. When you cloned the repo and checked out a working copy, it created the master branch for you. When you tried to push however, there was no master branch on the remote repo, so it complains.

Try using git push origin master (or whatever your remote is called) and it should create the branches on the remote for you.

sykora
  • 96,888
  • 11
  • 64
  • 71
  • Thanks for your reply. I did that and I am getting this error: `error: unable to create directory for .git/refs/remotes/origin/master error: Cannot lock the ref refs/remotes/origin/master.` –  Aug 31 '10 at 03:25
  • Pushing as root is just postponing the problem to the next guy who's trying to push. One needs to look carefully what user will gonna push to origin and what chmods are used. Setting up as multi user ain't rly that easy, unfortunately. – Manuel Arwed Schmidt Aug 29 '15 at 17:42
0

The second issue:

error: unable to create directory for .git/refs/remotes/origin/master
error: Cannot lock the ref 'refs/remotes/origin/master'.

shows up when your file ownerships and permissions are wrong. This message means that in the current workin repo you are trying to push from some files are not writeable. Take a look at the whole path down to .git/refs/remotes/origin/master to spot the issue. I would recommend to not sudo with git because this will create files etc. as unix user root and prevent anybody else to later work with this repo without sudo'ing all the time.

If you find yourself in a multi-user environement, you might create a new user git with empty password (no ssh for that user!) that can be switched to with su git (su = switch user) which handles all the pushing/fetching/cloning etc. This is essentially what a deamonized setup would also do (one user for any meta files) but might have some advantages in some circumstances.

Manuel Arwed Schmidt
  • 3,376
  • 2
  • 18
  • 28