While working on a feature branch, I use this Git command to update my "develop" branch to the latest state, immediately before merging my feature branch with the "develop":
git fetch origin develop:develop
fatal: Refusing to fetch into current branch refs/heads/develop of non-bare repository
fatal: The remote end hung up unexpectedly
The comment is instructive:
Some confusing tutorials suggested that it would be a good idea to fetch into the current branch with something like this:
git fetch origin master:master
(or even worse: the same command line with "pull" instead of "fetch").
While it might make sense to store what you want to pull, it typically is plain wrong when the current branch is "
This should only be allowed when (an incorrect) "
git pull origin master:master" tries to work around by giving
--update-head-okto underlying "
git fetch", and otherwise we should refuse it, but somewhere along the lines we lost that behavior.
The check for the current branch is now only performed in non-bare repositories, which is an improvement from the original behaviour.
Considering that the function
check_not_current_branch() is called with:
if (!update_head_ok) check_not_current_branch(ref_map);
That means a
git fetch -u origin develop:develop should work.
By default git fetch refuses to update the head which corresponds to the current branch. This flag disables the check.
This is purely for the internal use for
git pullto communicate with
git fetch, and unless you are implementing your own Porcelain you are not supposed to use it.
Even though you are not supposed to use that option, it does answer your initial requirement, making “
git fetch origin branch:branch” work on a current branch.
Regarding the origin of this patch, follow the discussion there.
While it might make sense to store what you want to pull
That is the
fetch part: it stores the remote history from the updated
But that is especially broken when the current local branch is also
As mentioned in this answer:
I think "
git fetch url side:master" when
masteris the current branch and we have omitted
The test fails on current
It would also fail to update the working directory and would leave the index as if you're removing everything.