PhpStorm And Git SSH Keys

PhpStorm has amazing git integration. Pulling (cmd+t) and committing (cmd+k) work like a charm and are visualised well. During a commit you can even select a file and hit cmd+d to see a last-minute diff of the changes you're about to commit. In that window you can still fix any mistakes that were about to be committed.

I set up a project recently that required a public SSH key to be on the server in order for me to gain access to the git repository. But when performing a git pull PhpStorm told me this:

Fetch failed: fatal: Could not read from remote repository.
Update canceled

No more information than that.
Now, `git pull` on the command line worked like a charm and debugging the SSH connection with `ssh -vvv my.git.host` obviously didn't show any problems.

The problem stems from the fact that PhpStorm uses the default public key to connect to a git repository and it expects it to be named "id_rsa".

I have multiple projects set up on different git hosts and it always seemed to take the right key. What happened to be the case though was that my ~/.ssh/config file always happened to have the hostname of git host as its "Host" entry.

This time I had set it up so that "Host" was named something else and "HostName" had the actual fully qualified domain name.

Of course when PhpStorm pulls or pushes to the git repository it checks the config file of the project's .git folder and that will have the actual hostname in there. It _does_ check for an entry in your ~/.ssh/config file but in my case it did not find a "Host" entry with the name it was looking for. When PhpStorm does not find a matching entry in ~/.ssh/config it will default to using the key with name id_rsa.

I did not have an ida_rsa & id_rsa.pub key pair in ~/.ssh so PhpStorm failed to connect to the git repository.

The two things you can do to fix this are:

1) copy the public and private key-pair you'd like PhpStorm to use to id_rsa.pub and id_rsa respectively

or

2) Rename the "Host" entry in ~/.ssh/config to actually match the domain in the project's .git/config file