Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git refusing to fetch into current branch

Tags:

git

git-fetch

I set up a remote repository and I can push new changes to it, but I cannot fetch from it, I always get the (rather cryptic) error message:

fatal: Refusing to fetch into current branch refs/heads/master of non-bare repository fatal: The remote end hung up unexpectedly 

What does it mean? What should I do to enable fetching?

(Note that this remote repo is only used as a backup repo, so it should be pretty much an exact copy of my local repository. I really can't understand why I can push to it but not fetch from it...)

My config looks like:

[remote "origin"]     url = ssh://blablablah     fetch = +refs/*:refs/*     mirror = true 
like image 268
Olivier Verdier Avatar asked Feb 10 '10 12:02

Olivier Verdier


People also ask

How do I pull just the current branch?

Git already only pulls the current branch. If you have branch set up as a tracking branch, you do not need to specify the remote branch. git branch --set-upstream localbranch reponame/remotebranch will set up the tracking relationship. You then issue git pull [--rebase] and only that branch will be updated.

Does git fetch update all branches?

git fetch. On its own, git fetch updates all the remote tracking branches in local repository. No changes are actually reflected on any of the local working branches.

Does git pull always fetch?

Git Pull Doesn't Do A Git Fetch.


2 Answers

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.

like image 160
RobW Avatar answered Sep 26 '22 18:09

RobW


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/*.

like image 41
Michael Krelin - hacker Avatar answered Sep 26 '22 18:09

Michael Krelin - hacker