0

I am a newbie in git and currently trying out various combinations to understand git.

I have a repository with branch named 'dev'. Now initially i brought my local in sync with the remote. Then i changed the remote directly from Github.

Now if i use

git fetch origin dev:dev

then i receive an error

fatal: Refusing to fetch into current branch refs/heads/dev of non-bare repository

However, the following pull command works fine

git pull origin dev

In one of the Stackoverflow answer it was mentioned that fetch followed by merge was equivalent to git pull.

If it is so then why this discrepency ?

Question Link : understanding git fetch then merge

PS : The answer suggested from link below in comments is correct one. However i was wondering that

git fetch origin 

fetches from all branches including the current one. Then why perform the check only in case of

git fetch origin master:master

I am not able to understand the reason behind this validation. Any help is appreciated.

Thanks

Community
  • 1
  • 1
harsrawa
  • 422
  • 5
  • 18
  • Actually `pull` is a shortcut for `fetch` + `merge`. But `dev:dev` arguments is the making difference there. Please, take a look to this answer: http://stackoverflow.com/a/32561463/2104879 – mertyildiran Sep 20 '16 at 22:55
  • Hi Mertyildiran, Thanks for helping me out. The answer you suggested is the correct one. – harsrawa Sep 20 '16 at 23:12

1 Answers1

0

fatal: Refusing to fetch into current branch refs/heads/dev of non-bare repository

This error generally means that you're fetching a branch that doesn't have a remote branch. I'm making some assumptions here that you want to fetch from the origin repo and merge in the latest changes from dev to your local branch. If this is the case, then you want to try out following :

git fetch origin
git merge origin/dev
blr
  • 908
  • 4
  • 8
  • If fetch only downloads changes from the remote branch and updates the repository data, but leaves the local branch unchanged, what is the point of fetching if the working directory will not show/reflect the changes? My question originally was that how could I see the changes someone else has done and then decide whether I would like to merge them into my working directory (i.e. experiment with other people's changes to make sure it does not break my work) but I am still confused how to do that. Should I just pul and experiment/explore, and if it was problematic, do a hard reset? –  Jun 09 '18 at 17:10