killachaos
killachaos

Reputation: 424

git push results in permission denied or (branch is currently checked out)

I have cloned a remote repository and made a few commits. I am trying to push my commits back to the repository so other developers can fetch them. First I tried: git push "other_serv" my_branch:master but I got

remote: error: refusing to update checked out branch: refs/heads/master[K
remote: error: By default, updating the current branch in a non-bare repository[K
remote: error: is denied, because it will make the index and work tree inconsistent[K
remote: error: with what you pushed, and will require 'git reset --hard' to match[K
remote: error: the work tree to HEAD.[K
remote: error: [K
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to[K
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into[K
remote: error: its current branch; however, this is not recommended unless you[K
remote: error: arranged to update its work tree to match what you pushed in some[K
remote: error: other way.[K
remote: error: [K
remote: error: To squelch this message and still keep the default behaviour, set[K  
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.[K
To user@server:/path/to/git
! [remote rejected] my_branch -> master (branch is currently checked out)

So I googled the problem and on the remote server tried:

git checkout -b dummy

Then tried to push again but got the same error. So instead of pushing to the master I tried to push to dummy. Then I got this error:

error: Unable to append to ./logs/refs/heads/dummy: Permission denied
To user@server:/path/to/git
 ! [remote rejected] my_branch -> dummy (failed to write)
error: failed to push some refs to 'user@server:/path/to/git'

So I searched so more and found out some people had problems with their permissons. So I chmod'd and chown'd all the files:

-rw-rw-r-- 1 user git   41 2011-06-20 20:07 dummy
-rw-rw-r-- 1 user git   41 2011-06-19 19:47 master

and I am able to write to both dummy and master, but I still get the error above. Anyone have any solutions? I've been banging my head at this supposedly simple problem.

EDIT: Seemed to have found the root cause. For some reason my repo is located at /path/to/repo.git even though all the commands I use point to /path/to/repo. Is this part of git?

EDIT 2: Turns out there was a second folder called ./repo.git. Since the ./repo folder was bare, git was searching ./repo.git for the ./repo files rather than ./repo. It seems when searching for ./.git, git prefers ./repo.git/.git over ./repo when the git config files are inside ./repo

Upvotes: 2

Views: 4336

Answers (1)

gahooa
gahooa

Reputation: 137432

When you setup a remote repository, it is best to use a bare repository...

git clone --bare YourRepo/ YourRepo.git
rsync -azv YourRepo.git [email protected]:

Now clone it over ssh:

git clone ssh://[email protected]/~/YourRepo.git
... edit ...
git commit ...
git push origin HEAD

Using a non-bare repository, as the error message said, has some issues with permissions. A bare repository does not have an associated working directory, and therefore is free of that complexity.

Upvotes: 1

Related Questions