Unable to push to remote GIT repository — “[…] doe

2019-04-11 19:36发布

问题:

I've set up my GIT repository on my server using the following in the appropriate folder (the root of my subdomain, git.mydomain.com):

mkdir foo.git
cd foo.git
git init --bare --shared

This would make the repository available by the URL git.mydomain.com/foo.git.

On my client, trying to push the commited files to the server using the following: mkdir foo

cd foo
git init
git remote add foo myUser@git.mydomain.com:foo.git
git add readme.txt
git commit -m "foo"
git push foo master
.. entering user password ..

Only results in:

fatal: 'foo.git' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

However, following a set of different guides, I seem to be unable to resolve this problem. Any suggestions would be highly appreciated, please bear in mind that I'm quite green to GIT.

回答1:

The line git remote add foo myUser@git.mydomain.com:foo.git assumes that the directory foo.git is in the home directory of the myUser user. You're much better off using an absolute path e.g. git remote add foo myUser@git.mydomain.com:/home/gitrepos/foo.git

If you're on a shared server, you can check your home path by executing:

echo $HOME

Which, in my case, yields:

home/u/01234/

If I've stored my repositories in the www/git/ folder in my home-path, the command might look something like this:

git remote add origin myUser@mydomain.com:/home/u/01234/www/git/foo.git