git refusing to fetch into current branch

What you're trying to do is to fetch the branch you're workin on. That is, you are on the master branch and you try to update it. That's not possible. It's more common to update the remotes/* branches and then pull it into your local ones. What you want is, perhaps,

git remote add otherrepo thehost:/the/path.git

That will setup repository to be fetched into remotes/otherrepo/*. git fetch otherrepo should do the trick. Alternativeley, you can manually edit your .git/config and set fetch for the remote to something like refs/heads/*:refs/remotes/otherrepo/*.


In case anyone finds this because they specifically want to fetch into the current branch, you can use the --update-head-ok flag. From the docs:

-u
--update-head-ok
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 pull to communicate with git fetch, and unless you are implementing your own Porcelain you are not supposed to use it.

In some cases we do want to implement our own porcelain commands, e.g., automation and tooling.

Tags:

Git

Git Fetch