0

I have a git repo on my local machine. I push (initially) this to a remote(web server) , I checkout the remote (on the remote) so that files can be served by apache, I change a file on my local, commit -a it and then I try to push it again and I always get an error. This was pretty simple with Svn , How do I do this with git?

Counting objects: 5, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 298 bytes, done.
Total 3 (delta 2), reused 0 (delta 0)
remote: error: refusing to update checked out branch: refs/heads/Dev
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 inconsist
ent
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'.
To ssh://mike628@192.168.2.2/var/www/UML/.git
 ! [remote rejected] Dev -> Dev (branch is currently checked out)
error: failed to push some refs to ......'
mike628
  • 45,873
  • 18
  • 40
  • 57
  • 4
    I don't see any error... – KingCrunch Jul 12 '11 at 22:56
  • Since this isn't programmers jeopardy, it would be great if you'd also post the error. – moritz Jul 12 '11 at 22:59
  • possible duplicate of [git push error 'remote rejected\] master -> master (branch is currently checked out)'](http://stackoverflow.com/questions/2816369/git-push-error-remote-rejected-master-master-branch-is-currently-checked-ou) – manojlds Jul 12 '11 at 23:45

2 Answers2

0

You should not push to a non-bare repository. Have a 3rd repo that periodically pulls from the one that you push to. Git won't alter your remote's working dir without you doing it explicitly from the remote side.

You are dealing with a DVCS and the concept of push vs pull is an important one.

For more info see progit.org/book.

Hope this helps.

Adam Dymitruk
  • 124,556
  • 26
  • 146
  • 141
0

Temporarily, create a new temporary branch on your server to allow you to push:

git checkout -b temp

This makes sure that the current branch you are pushing to is not checked out. Now your push from local should go through.

There is a concept of bare and working repos in Git, and "central" repos - repos that you push to, are generally bare. It is a best practice and will prevent you from a lot of pain. You can also convert your current repo on the server into a bare repo:

git config --bool core.bare true

( then delete everything except .git)

Or, follow what @adymitruk says. Learn more about Git and DVCS before proceeding.

manojlds
  • 290,304
  • 63
  • 469
  • 417