32

When I do a git push, I see the following:

warning: updating the currently checked out branch; this may cause confusion,
as the index and working tree do not reflect changes that are now in HEAD.

I Googled for this message, and all I can find is a git mailing list discussion where the authors try to decide exactly how to make this message better to communicate to me what the real problem is.

How did I cause this, and how do I fix it?

skiphoppy
  • 83,104
  • 64
  • 169
  • 214
  • 2
    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) – Will Tate Feb 14 '13 at 21:34
  • 1
    @WilliamTate no, this post deals with a warning, linked post deals with error – CharlesB Feb 14 '13 at 21:58
  • 2
    Yes it is, I think it's the warning you received instead of the error in previous versions of Git. – Nowhere man Feb 15 '13 at 17:01
  • 1
    Possible duplicate of [What is this Git warning message when pushing changes to a remote repository?](https://stackoverflow.com/questions/804545/what-is-this-git-warning-message-when-pushing-changes-to-a-remote-repository) – Trevor Boyd Smith Sep 18 '18 at 16:44

3 Answers3

47

This happens when you are pushing to a non-bare repo. A bare repo is one that consists solely of a .git directory; a non-bare repo also includes a checkout. In general, you should not push to a non-bare repo; in fact, in future version of git, that will be forbidden. If you push to a non-bare repo, then the HEAD of that repo will be out of sync with the index and the working copy.

If you're creating a repo that people are going to want to push to, then you should create it using git init --bare (and git init --bare --shared if several user accounts need access to it), or git clone --bare if you're creating it by cloning an existing repo.

Brian Campbell
  • 289,867
  • 55
  • 346
  • 327
  • 1
    Thank you. This important warning was telling me that I was cloned from and pushing to the wrong repository!! I have a bare repository, similarly named to another repository which I accidentally cloned! – skiphoppy Apr 10 '09 at 18:14
  • 1
    Is it okay to pull from a non-bare repository to a non-bare. I guess not? – Keyo Dec 14 '10 at 05:48
  • 1
    @Keyo Yes, it's fine to pull from one non-bare repo to another. But you shouldn't push into a non-bare repo. – Brian Campbell Dec 14 '10 at 21:48
  • 2
    Actually, you can push to a non-bare repository just fine, you just can't push to the one branch that is **currently checked out**. – Nowhere man Feb 15 '13 at 17:03
  • 1
    @Nowhereman This is true, my answer is a bit of a simplification. In general, pushing to a non-bare repo is discouraged, even if only pushing to the currently checkout out branch would actually break anything. If you find yourself pushing to a non-bare repo, it probably means you're doing something wrong. – Brian Campbell Feb 15 '13 at 22:33
  • I'm not sure I've ever seen it discouraged, and I know of several perfectly valid workflows with Git that involve pushing to a non-bare repo. For example, I routinely version palintext notes with git, one repo on my laptop and one on my workstation. On each computer, a different branch is checked out so I can safely push it to the other computer, where I'll merge (I usually try to only do fast-forwards or I rebase). – Nowhere man Feb 16 '13 at 03:23
12

In short, your remote repository is no longer a bare one, and you pushing on the remote checkout branch.

See "How to publish a Git repository":

A bare repository is one without a checked out working copy of the code. It only contains the git database.
As a general rule you should never push into a repository that contains changes in the working copy.
To ensure this doesn't happen, we're making the server repository a bare repository - it has no working copy

From here:

Note that the target of a "push" is normally a bare repository (i.e., with no work tree of its own).
You can also push to a repository that has a checked-out working tree, but the working tree will not be updated by the push.
This may lead to unexpected results if the branch you push to is the currently checked-out branch.

If a detached work tree is defined (which can for instance correspond to a web server's DocumentRoot), you need to :

Check, on your remote repository, the value of git config core.worktree and git config core.bare

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • 1
    Note to self: see http://stackoverflow.com/questions/2041823/2041865#2041865 for an example of bare repo usage. – VonC Jan 20 '10 at 14:46
5

I made my repository bare by cloning a new, bare, repository from my messed up one, saving the messed-up one just in case, and replacing it with my cloned bare one.

I'm new to git, and when I set up the repsitory, I forgot to use the --bare option. Thanks for all your help!

I've since read the O'Reilly git book and now am a total git convert.