LeonardChallis
LeonardChallis

Reputation: 7783

Why is Git trying to connect to the wrong host?

I have a LAMP system setup on CentOS. I also have git setup on the same server with a centralized workflow (we have just moved over from SVN). I have multiple repositories now cloned around the system, using the following syntax:

git clone git:someexistingrepository.git

This is working fine. Now, I had an existing directory I wanted to convert in to a git working direcory. I followed the instructions from the accepted answer to this question. As I have been using the local server, I used the following command:

git remote add origin git:myrepo.git

myrepo.git was already setup with:

git init --bare myrepo.git

I have done this before and I've not had any problems, however this time I did, when I ran:

git push -u origin master
The authenticity of host 'git (173.192.58.115)' can't be established.
RSA key fingerprint is b1:43:2f:b0:7e:2f:ba:74:6f:19:2e:b8:35:81:10:b6.
Are you sure you want to continue connecting (yes/no)? ^C

I looked up that IP address and it is apparently one used by git.co.uk - obviously nothing to do with me (or Git). Is there some weird behaviour happening here, or can anyone suggest some incorrect config I may have? I read that using git:reponame.git was the right way (I'm afraid I can't find the SO question I read this on sorry) - is this so?

Update

Note: I'm using the SSH protocol, not git. Also, the config file inside .git looks like this:

[remote "origin"]
        fetch = +refs/heads/*:refs/remotes/origin/*
        url = git:somerepo.git

This is the same for both the cloned repositores and ones using the method described above, so I don't know why one is resolving to that host and one isn't. Using git:// gives the (expected) error:

git clone git://bugs.git
Initialized empty Git repository in /tmp/bugs/.git/
fatal: Unable to look up  (port 9418) (Name or service not known)

Update 2

Thanks to the hints and answer from Oskar N, and that I realised that the root user had this problem whereas other users hadn't, I finally realised that I'd originally set something up in /etc/skel...

[user@host ~]$ cat .ssh/config
Host git
        Hostname localhost
        User git
        IdentityFile ~/.ssh/id_rsa

So, git was the host (and the answer correct, thanks!). When I ran resolveip I was in the root screen, adding something to /var/www/ as it's all owned by root. Luckily my other sites are setup with users.

Upvotes: 4

Views: 1823

Answers (1)

Oskar N.
Oskar N.

Reputation: 8587

Repository is a URL. The "git:" part means it should lookup the hostname "git", which on your system resolves to git.co.uk. I believe the SO question you saw actually used git:// which means to use the git protocol.

For SSH you should use either ssh://user@hostname/path/to/reponame.git for absolute paths or user@hostname:path/to/reponame.git for relative paths. If you're cloning on the same system, simply use reponame.git as the URL.

Upvotes: 3

Related Questions