Git – How to Pull/Fetch Into a Bare Repository

gitgit-fetchgit-pull

I'm writing a tool to backup all my repositories from Bitbucket (which supports Git and Mercurial) to my local machine.

It already works for Mercurial, where I do it like this:

  • create a new empty repository without a working copy on the local machine
    (the same like a bare Git repository)
  • pull from the remote repository into the local empty repository

Now I'm trying to do the same with Git.

I already found out that I can't directly pull to a bare repository and that I should use fetch instead.

So I tried it:

C:\test>git fetch https://github.com/SamSaffron/dapper-dot-net.git
remote: Counting objects: 1255, done.
remote: Compressing objects: 100% (1178/1178), done.
remote: Total 1255 (delta 593), reused 717 (delta 56)
Receiving objects: 100% (1255/1255), 13.66 MiB | 706 KiB/s, done.
Resolving deltas: 100% (593/593), done.
From https://github.com/SamSaffron/dapper-dot-net
 * branch            HEAD       -> FETCH_HEAD

Obviously Git did fetch something, but the local repository is empty after that.
(git log says fatal: bad default revision 'HEAD')

What am I doing wrong?

Disclaimer:
I have only very, very basic Git knowledge (I usually use Mercurial).
And I'm using Windows, if that matters.

Best Answer

Try

git fetch https://github.com/SamSaffron/dapper-dot-net.git master:master