Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does git "updating currently checked out branch" warning mean?

Tags:

git

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?

like image 768
skiphoppy Avatar asked Apr 10 '09 16:04

skiphoppy


People also ask

What does it mean when a branch is checked out?

Checking out branches Checking out a branch updates the files in the working directory to match the version stored in that branch, and it tells Git to record all new commits on that branch. Think of it as a way to select which line of development you're working on.

What does git checkout period do?

The git checkout - command lets you switch to the last branch you were on without actually typing the branch name. It's like the “last” button on your remote control. This can be a bit confusing, because earlier I told you that git checkout -b <branch-name> would create a new branch and switch you to that new branch.


2 Answers

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.

like image 123
Brian Campbell Avatar answered Oct 22 '22 22:10

Brian Campbell


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 :

  • have a post-receive hook on your remote repository (like the one described here), running "git checkout -f" and
  • ignore the warning message (git config receive.denycurrentbranch ignore)

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

like image 12
VonC Avatar answered Oct 22 '22 22:10

VonC