0

I am using 1und1.de service for GIT they offer. Now I am setting it up and I pulled the changes to my local computer from there with the command git pull ssh://.........

but when I tried to to git push ssh://...... I received a lot of errors:

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 incosistent

Auto packing the repository for optimum performance.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 arranged to update its work tree to match waht you pushed in some other way.

remote: error: to sqelch 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)
error: failed to push some refs to 'ssh://........' 
TooCooL
  • 20,356
  • 6
  • 30
  • 49
  • How did you setup the repo? Did they do it for you? – manojlds Mar 23 '13 at 19:01
  • no, I did, I just typed in the: git init command, do you think I should have done something like git init --bare.. or maybe I need to configure it to accept git push? – TooCooL Mar 23 '13 at 19:05

2 Answers2

1

When you are setting up a repository that you intend to push to, set it up as a bare repository:

git init --bare

Though it is technically possible to push to a repo with working directory, it is too much of a headache, and in this case, you don't even want that.

Just recreate the repo as a bare one or create a bare one from it (git clone --bare /path/to/repo)

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • I want the existing git remote to change to bare repo but I am afraid I might do something wrong and change the files in my server – TooCooL Mar 23 '13 at 19:19
  • @TooCooL - Clone the repo to a different locations like so `git clone --bare /path/to/repo`. See if it works. And then replace the old one – manojlds Mar 23 '13 at 19:21
  • Is it possible to delete the .git file in the server to delete everything from this git repo, then run the command git init --bare and add the files to git tracking, I dont care about the commits because I dont have commits, just one when I started it. – TooCooL Mar 23 '13 at 19:23
1

There are two types of Git repository. A bare repository is usually called foo.git and doesn't have a working tree, just Git's internal files. A non-bare repository is a working tree (that is, a directory with all the files) which also contains a directory named .git. As the error message explains, pushing into a non-bare repository is usually a bad idea, because when you do that the working tree becomes out of date against the repository.

When you're hosting a repository for people to pull from and push into, you almost always want a bare repository. It seems like in this case you've created a non-bare repository. Since you don't give any details of how you created the repository, I can't tell you what you did wrong, but you can create a bare repository in one of two ways:

  1. From the directory where you want to create the repository, issue git clone --bare path/to/original.git. That will clone the source to a bare repository original.git inside the directory you're in.
  2. From the directory where you want to create the repository, issue git init --bare foo.git. This will create an empty bare repository foo.git inside the directory you're in.

There are more things you can do, but they're the easiest to get right. Issuing git config --set core.bare false inside an existing repository will make Git think it's a bare repository from then on, but you have to delete the working tree yourself, and you should probably rename the repository from .git to foo.git.

Dan Hulme
  • 14,779
  • 3
  • 46
  • 95