Issue
I try to view my remote branches:
git fetch --all
I get the error message:
fatal: '/html/project' does not appear to be a git repository
Could not read from remote repository.
Please ensure that the correct access permissions exist and the repository exists.
So I logged in via ssh to my server and navigated to my folder /html/project
and typed git status
.
I get a git output so html/project is a git repository. I also checked the folder permissons of the folder html/project
:
drwxrwxr-x 11
So why are these error messages?
Solution
git fetch --all
This means "fetch from all remotes". How many remotes do you have? What are their URLs? (Use git remote -v
to list them.)
I get the error message:
fatal: '/html/project' does not appear to be a git repository Could not read from remote repository. Please ensure that the correct access permissions exist and the repository exists.
This means that at least one of your remotes—we won't know which one(s) until you run git remote -v
to list them—has /html/project
as its (Git-extended-style) URL. Or—here's the tricky bit—perhaps one of them has ssh://<ssh-part>/html/project
.
So I logged in via ssh to my server ...
That's fine, but it misses out on the tricky part.
... and [
/html/project
on that computer is a Git repository]
It sounds like your URL should be ssh://your.server.full.dns.name.goes.here//html/project
or similar, rather than just /html/project
. (Whether you need a user name here depends on how your ssh login to this server works.)
Note the double slash!
You mention in comments that the URL is:
ssh://[email protected]:2222/html/sulu
(for both fetch and push), and that's the problem. Even with the ssh://[email protected]:2222
part, which directs your Git to (in effect) use ssh -p 2222 [email protected]
to get to the remote, the URL your Git provides to [email protected]
is not /html/sulu
but rather html/sulu
.
Git isn't really aware of all of this—it doesn't do a lot of fancy parsing work—so Git thinks it's presenting /html/sulu
, but it isn't. It's presenting html/sulu
.
When ssh connects to another machine, you start out with your current working directory being your home directory. For instance, my home directory is /home/torek
(Linux) or /Users/torek
(macOS). So any relative URL, as for:
ssh://my.host.name/src/proj
refers to /home/torek/src/proj
or /Users/torek/src/proj
. But you want /html/sulu
, something not in your home directory.
You can typically get there by using the double slash trick: ssh://[email protected]:2222//html/sulu
. The ssh code strips off one slash, leaving /html/sulu
as the path, which then works.
Sometimes the ssh system doesn't let you do this—it's all up to ssh; none of it is up to Git—and in that case you may need to use some other trick, such as making a symbolic link in your home directory on the server.
Answered By - torek Answer Checked By - Timothy Miller (WPSolving Admin)