Cannot get git extensions to push something to git

2019-02-13 14:44发布

问题:

Im trying to use git extensions and I really like it so far, but I don't manage to push to github. The following command works fine in git bash:

git push "origin" master:master

and then when I push with git extensions I get this:

C:\Program Files\Git\bin\git.exe push "origin" master:master
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

Done

In the git settings it just has openSSH selected which I would like to keep because putty seems more hassle.

The remote addres I have added in gitextensions, actually the only thing I have done from the bash just to test is the command above and gerenating the SSH keys. All else is set up in git extensions. So I suppose everything must be set up correctly. Eg, the email adress and name are correct...

ssh git@github.com

also connects fine, from bash

edit:

So I can reproduce the error by putting the command from git-extensions in cmd. Appearantly there is a difference between running from git bash and from cmd and git-extensions runs this command like a windows command... any clues?

update: If I choose git-bash from the menu in git-extensions I get a window that is exactly the same as when I right click in explorer on my repo folder and choose git bash here. Now, in the one opened from explorer I can push and in the one opened from extensions I get the public key problem.

回答1:

Things to check for:

  1. Presence of HOME environment variable.
  2. Presence of %HOME%\.ssh\ and RSA keys there.

When you run git from command promt it is preferred to run git.cmd, because it fixes HOME automatically:

@if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH%
@if not exist "%HOME%" @set HOME=%USERPROFILE%

To fix gitextensions, define HOME variable and set it to same value as USERPROFILE



回答2:

Ok, I solved it.

I opened the git bash from git extensions and a git bash using the explorer shell extensions. I then ran ssh -vvv git@github.com from both to see the difference.

It turned out that because I changed the location of the git config file ( I tend to reformat every now and then, so c:\documents and settings... is notoriously bad for storing anything I might want to keep persistent), when run from git extensions git was also looking for the ssh keys in a different location. So I added the .ssh folder where my git cofig file is and now it works fine. I think git-extensions sets the HOME variable for git to whatever you set as path for the config file.

Now, that was not obvious...



回答3:

The correct answer is the one from 'max' (set your HOME env var manually), but it may help some to understand why the problem is happening (as Git gets more users around the world it's going to be very common).

Cygwin sets $HOME to /home/yourname, but that variable is not known in the Windows environment. So if you open a bash window and do env | grep HOME you'll see all three 'HOME' variables mentioned here, and you might wonder why Gitextensions doesn't use your proper cygwin HOME - which is because its .bat file invocation doesn't see it - it only sees what you see from doing 'set' in a windows console.

It's mystifying why it doesn't do this evaluation later and get the proper cygwin path since it knows how to invoke bash, but (at least in versions up to 2.41) you have to do this manual change in the settings or in .gitconfig.



回答4:

When you fire up git bash directly you'll land in your home folder for MSYS. You need to make sure you have your ssh key (id_rsa ?) in the .ssh subfolder (relative to the home folder).



回答5:

Glad you solved the problem. Since this sounds like a serious problem I'm interested in the difference between git-bash when started from GitExtensions. In GitExtensions there is a setting that might fix this. The %HOME% directory can be changed in GitExtensios. By default it will be set to %HOMEDRIVE%%HOMEPATH%, but you can override this. Changing this probably solves your problem, since you suggest this is the problem. To change this open the settings dialog and go to the tab "git". In the section "Environment" you can set the %HOME% path.

I will appreciate it if you let me know if this also solves the problem. I'm also interested in what caused this in the first place. Maybe I can improve the check for a valid HOME directory.



回答6:

Yes, not setting the HOME varible was the issue for me too.

Set the HOME variable as %USERPROFILE% and regenerate the Private and Public keys, then try cloning—it should work now.



回答7:

I see that the HOME variable is set to USERPROFILE in git extensions. I can add and commit but not push/pull from the remote repository. I am unable to connect to any remote repository. We use http (not ssh) for the connection. However, using git bash I am able to connect to the remote and do push/pull. I had put my issue GIT extensions does not connect to remote but git bash does and was directed to this issue. However, I am unable to resolve my issue. Any ideas?