The receive.denyCurrentBranch
config option controls what happens if you push to a repo's branch that is checkout.
By default, it rejects it (which is why you usually only push to bare repos, which have no checkout branches).
It can be disabled via ignore
or warn
.
Another option is updateInstead
.
What this does is that if the HEAD
and working directory are the same, and the branch being pushed is HEAD
, both the working directory and the branch/HEAD
are updated at the same time.
If the working directory is different from HEAD
, the push is rejected.
This is useful, for pushing to webservers, for example.
My question is, does this option interact with the Index at all?
Is the Index updated? What if HEAD
and the working directory match, but not Index
?
Is the Index updated? What if HEAD and the working directory match, but not Index?
Commit 0855331 (git 2.4.0-rc0, Dec. 2014) states it clearly:
When
receive.denyCurrentBranch
is set toupdateInstead
, a push that tries to update the branch that is currently checked out is accepted only when the index and the working tree exactly matches the currently checked out commit, in which case the index and the working tree are updated to match the pushed commit.
Otherwise the push is refused.
Although that same commit introduced the push-to-checkout
hook.
This hook can be used to customize this "push-to-deploy" logic.
The hook receives the commit with which the tip of the current branch is going to be updated, and can decide what kind of local changes are acceptable and how to update the index and the working tree to match the updated tip of the current branch.
That gives a bit of flexibility regarding the index.
Commit 1a51b52, git 2.4.0-rc2, Apr 2015 says it again:
Setting
receive.denycurrentbranch
toupdateinstead
and pushing into the current branch, when the working tree and the index is truly clean, is supposed to reset the working tree and the index to match the tree of the pushed commit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With