user650261
user650261

Reputation: 2264

Git clone: "You appear to have cloned an empty repository"

Some colleagues and I have been working on a project stored in a private Git repository. Historically, there have been no problems, but recently I attempted to clone and got the following problem:

Cloning into 'project'...
warning: You appear to have cloned an empty repository.
Checking connectivity... done.

A git log provides:

fatal: your current branch 'master' does not have any commits yet

This isn't correct - my colleague pushed plenty of non-empty changes on Dec. 6 (although now that branch isn't showing on a --single-branch clone attempt). After ssh-ing into the Git repository, there is plenty of files and folders there.

So, my questions:

  1. How could this have happened?
  2. How can we recover the repository? It seems the stuff is on the remote repo, but for some reason, it isn't aware that it's there.

Upvotes: 16

Views: 76336

Answers (7)

closedloop
closedloop

Reputation: 711

I ran into the same issue that turned out to be a from a race condition:

gh repo create xxx --template template-name
gh repo clone xxx

This resulted in cloning of empty repositories.

By adding a delay (I did 15 seconds but I'm sure a much smaller interval would work)

gh repo create xxx --template template-name
sleep 15
gh repo clone xxx

Upvotes: 0

KevinLiu
KevinLiu

Reputation: 213

I encountered the same issue after migrating to a new Gitlab server.

It has been fixed after performing the steps below.

For example, if the project Git URL is http://gitlab.abc.work/neptune-open/neptune-developer-guide.git

  1. Clone the repo
    git clone [email protected]/neptune-open/neptune-developer-guide.git
    
  2. Edit the local Git config (for example, with vi):
    vi neptune-developer-guide/.git/config
    
    Then change the "origin" url to http format:
    [remote "origin"]
        url = http://gitlab.abc.work/neptune-open/neptune-developer-guide.git
    
  3. Modify any file in the project
  4. Commit the modifications to the file
    cd neptune-developer-guide && git add . && git commit -m "fix git clone issue"
    
  5. Push it
    git push origin master
    

Upvotes: 0

Alex.K
Alex.K

Reputation: 294

A colleague of mine just had a similar issue. Frankly, I have no idea why it happened, since a simple HTTPS cloning worked for the rest of our team. But, ultimately, here's a solution that helped - instead of git clone we had to do basically the same, but manually:

  1. Create an empty folder for your project, say project/
  2. In project/, run git init
  3. Add the remote: git remote add origin https://github.com/yourAccount/yourrepo.git
  4. Pull from the remote: git pull origin master

Upvotes: 0

robsch
robsch

Reputation: 9718

In my case it was a silly mistake when I've tried to clone a repo from another machine: I've used https instead of ssh as protocol in the URL. Surprisingly I've got no error, but the message “You appear to have cloned an empty repository”.

Upvotes: 0

Mohammed Muzammil
Mohammed Muzammil

Reputation: 704

This happens when you are cloning a freshly created repository with no commits.

As it says, it is just a warning. If it is expected that there is nothing in the repository, you can go ahead and add files and commit and push back.

If it is not supposed to be empty, contact the person/admin who gave you the link.

Upvotes: 4

Jun Aid
Jun Aid

Reputation: 504

You have cloned the correct repository. I think they have not pushed into the master branch. The other branches will be there like origin/development-example. You need to make a local branch which can track the remote branches and then you can get the latest code. This is how you can track remote branches:

git branch --track dev-example origin/dev-example
git checkout dev-example

Upvotes: 6

Emile Bergeron
Emile Bergeron

Reputation: 17430

If the repo is hosted on a gitlab server, and you used git over http to clone the repo, it could be related to this:

Git over HTTP will receive an empty repo if giltab-git-http-server is not properly configured

If for some reason gitlab-git-http-server is not properly configured, or you are using a custom nginx or Apache proxy that forwards directly to Unicorn and you attempt to clone via HTTP, the request succeeds, you receive a 200 and an empty repo.

A quick fix is to use git over ssh to clone the repo.

Upvotes: 10

Related Questions