git refusing to fetch into current branch

前端 未结 7 1593
不思量自难忘°
不思量自难忘° 2020-12-05 03:39

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 t         


        
7条回答
  •  爱一瞬间的悲伤
    2020-12-05 04:19

    I've had this problem when I thoughtlessly cloned a repository instead of fetching it, so that both repositories were masters. If you have done no work on the remote repository, you can fix things with the basic git commands as follows: (1) delete the remote repository, (2) copy the local repository to where the remote one was, (3) delete the local one, and then (4) set up the local repository using

    git init; git fetch $REMOTE_GIT_REPOSITORY_URL  
    

    Then git pull and git push will do the right things. The advantage of avoiding git remote, per Michael's more efficient and principled answer, is that you don't need to think about the semantics of tracking branches.

提交回复
热议问题