views:

2297

answers:

4

The description is a bit terse. I simply added a file on my local master branch and pushed it back to a remote repo. Any idea why this is coming up?

warning: updating the current branch
warning: Updating the currently checked out branch may cause confusion,
warning: as the index and work tree do not reflect changes that are in HEAD.
warning: As a result, you may see the changes you just pushed into it
warning: reverted when you run 'git diff' over there, and you may want
warning: to run 'git reset --hard' before starting to work to recover.
warning: 
warning: You can set 'receive.denyCurrentBranch' configuration variable to
warning: 'refuse' in the remote repository to forbid pushing into its
warning: current branch.
warning: To allow pushing into the current branch, you can set it to 'ignore';
warning: but this is not recommended unless you arranged to update its work
warning: tree to match what you pushed in some other way.
warning: 
warning: To squelch this message, you can set it to 'warn'.
warning: 
warning: Note that the default will change in a future version of git
warning: to refuse updating the current branch unless you have the
warning: configuration variable set to either 'ignore' or 'warn'.   
+28  A: 

Actually, it means pretty much exactly what it says: somebody is working in the repository that you are pushing to, and that somebody has currently checked out the exact same branch that you are pushing to.

This is very confusing, because now he thinks that he has checked out the latest version of the branch, when, in fact, you have just updated the branch to a newer version. So, when he now runs git commit, his commit will essentially revert all the commits that you just pushed. And when he runs git diff he will see the opposite of everything you just pushed, even though he maybe hasn't even changed anything.

For that reason, it is generally considered bad practice to push to a non-bare repository; you should only ever push to bare repositories, i.e. repositories that do not have an attached working copy. At the very least you should make sure that you do not push to the currently checked-out branch, but generally you shouldn't just shove your code into someone else's repository, you should ask them to pull from you instead.

In some special cases, like when you are serving a website from a Git repository and you want to update the website by pushing to it, it actually makes sense to push to the currently checked-out branch, but in that case you must make sure that you have a hook installed that actually updates the checked-out working copy, otherwise your website will never be updated.

Jörg W Mittag
The way I manage the website problem you mention in your last paragraph is to have a central bare repository that I push to, then I pull from that into the web site working directory. This method requires shell access to the web server, of course, where your hook method does not necessarily require that.
Greg Hewgill
Jorg, thanks for the response. The shared repository shouldn't have a working directory, but I did not init it with --bare. It's use is for sharing work only. There is a "work" area, but no one uses it. Should I re-init with bare?
Coocoo4Cocoa
+8  A: 

This is the same problem as This question, the solution is to use git init --bare or git clone --bare.

pluskid
`git clone --bare` did the trick for me. Thanks.
Hans W
+1  A: 

The remote repository I'm pushing to IS bare, and I still get this message all the time. Why it takes so many words to say absolutely nothing is beyond me.

Azeem.Butt
Please log this as a bug (with full details of you environment) on the git mailing list. This warning is not supposed to appear when pushing to a bare repository. The warning is deliberately verbose so that users don't ignore it as usually it indicates a dangerous operation. If you know what you are doing and want to squash the warning you can set the config option 'receive.denyCurrentBranch' on the remote repository to 'ignore'.
Charles Bailey
A: 

It says that even on bare repo. (all I did is upgrade git software from version 1.5 to 1.7)

sharad