17

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.
4
  • 3
    Did they push to a branch that isn't master? If so, do you just need to check out that branch? Commented Dec 19, 2015 at 19:52
  • 1
    You either cloned the wrong repository or they're lying to you (computers can't lie -yet-). Commented Dec 19, 2015 at 19:53
  • They pushed to a branch that isn't master, but as I mentioned, we are unable to check out that branch (or any other branch). I doubt he's lying :-) Commented Dec 19, 2015 at 19:56
  • This question is very similar to this other question but the answers on the old question were not really helping. Commented Aug 4, 2016 at 12:58

7 Answers 7

10

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.

Sign up to request clarification or add additional context in comments.

Comments

6

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 

5 Comments

There was a master previously. It has recently disappeared, and we don't know why. We are unable to track any other branches, because the remote isn't reporting that they're there. For instance: git branch --track symbolicPorts origin/symbolicPorts error: the requested upstream branch 'origin/symbolicPorts' does not exist hint: hint: If you are planning on basing your work on an upstream hint: branch that already exists at the remote, you may need to hint: run "git fetch" to retrieve it. hint: hint: If you are planning to push out a new local branch that...
check git fetch origin
Interestingly, that hung for a couple of seconds and then returned with no verbal output. It seems like it might have done something, but following that with a "git pull" returns: "Your configuration specifies to merge with the ref 'refs/heads/master' from the remote, but no such ref was fetched."
check git branch -r. This will tell you how many branches were fetched. If you find some new branches like origin/something then track those branches the way i told you in my answer.
git branch -r is blank.
4

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.

Comments

0

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”.

1 Comment

This question has long been irrelevant to me - we eventually pushed a local backup repository. But this is far and away the most plausible cause that I've heard so far. I wonder if it has something to do with configuration?
0

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

Comments

0

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 

1 Comment

Instead of manually editing the .git/config file, you can (you should) use git remote set-url (stackoverflow.com/q/2432764/2745495, git-scm.com/docs/git-remote#Documentation/…)
0

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 

1 Comment

To anyone reading this answer, gh is the Github CLI: cli.github.com/manual/gh_repo. If you are not using Github, simply replace the gh commands with your platform-specific CLI or maybe just with plain git commands. The important part of this answer is the sleep/delay part in between creating the repo and cloning it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.