ssh and GIT: couldn't resolve hostname - windows

Using Win7, Gitolite, and TortoiseGIT
today I updated my GIT to version 2.6.1, therefore I had to deinstall the old version.
Long time ago I created a ssh-config file to have easier access to my repositories and all was working fine since today.
After the update I tried to clone an existing repository and got following error:
ssh: couldn't resolve hostname gitbox: Name or service not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
Seems to me like GIT doesn't know where the ssh-config file is located.
Following helped but I'm not very happy with that solution:
Starting GIT GUI
Trying to clone a repository -> Same error as before
figured out that GIT created a new folder at /c/Users/newUser/
Inside the folder I found .gitconfig
Create .ssh folder here
Copy rsa key and config file here
All working as before
Can someone explain what happened here? Or how can I tell GIT/ssh where my config file was initially located?
Thank you very much!

Can someone explain what happened here?
You need to make sure that HOME is properly set to %USERPROFILE%: by default, git will look for the global config and for .ssh settings in %HOME%.
By default, calling c:\path\to\PortableGit-2.6.1-64-bit\git-cmd.exe would initiate a CMD session with HOME correctly set.
c:\path\to\PortableGit-2.6.1-64-bit\git-bash.exe would do the same for $HOME, in a bash session.

Related

Need help setting up a git server on windows

i'm trying to set up a git server on Windows, but i'm having some issues getting it all to work.
I have locally created a normal repository, and remotely i created a bare repository. On the local repository i added a single text file and committed it, but when I try to push it into the remote repository I always get the following message:
fatal: protocol error: bad line length character: fata
I searched SO and other sources, and most of them suggest it's an issue regarding command echos. I'm using freeSSHd as a SSH solution (remote repository is hosted on a windows server), and I tried to use both the git bash and the windows CMD as a command shell.
I start CMD with /Q to disable echoing and /K to change directory to a directory where repositories are located, so I don't think that would be a problem.
Using the remote desktop, i can clone the repository to a folder next to it, and using the git bash locally i can access the SSH shell and also clone the repository in the same way. But using git clone ssh://<address>:/myRepo.git I always get the above message (The SSH's working folder is the same where the repository is located). Does anyone have any idea what's going on? How can I see what command is triggering the error, and how can I see the full error message?
I also met the same error using freeSSHd as a ssh solution for git server on Windows. I couldn't find a solution for a whole day and gave up. :(
Later I found another powerful ssh server from Bitvise called WinSSHD worked well. It has free version for personal use. I suggest you to switch to it. Though I'd also like to know if there's a fix to the error we both met.
To setup ssh server with WinSSHD is quite simple, and you can add virtual accounts with private/public key access.
The key part is to setup the ssh access for git server. Please follow the steps of the blog here.
It should work well for Windows git client. For Mac, you may meet an error as follows.
grp.sh: No such file or directory
fatal: Could not read from remote repository.
To fix it, you need to create the two files gup.sh and grp.sh in your git bin directory (GIT_PATH/bin or GIT_PATH/libexec/git-core configured in system environment variable PATH) in your git server.
The content of gup.sh:
git-upload-pack.exe $*
The content of grp.sh:
git-receive-pack.exe $*

Git and SSH - How to know what address to use?

I need to set up a git repository in the production server so I can upload all my commits. So, these are the steps I followed:
Production Server (Windows Server 2008)
Installed Git
Created an empty repository at inetpub/wwwroot
Installed CopSSH
Created a new user account
Enabled the user with CopSSH
Changed the default directory of the new user to the repository address
Setted environment variables to read Git commands
Development (Windows 7 + Netbeans)
Installed Git
Created a repository right where my project is
Added all files of the project to the repository
Now, I need to upload my dev project to prod. First, I'm checking if the SSH default directory where I'm pointing to is a repository:
$ git ls-remote ssh://user#server/
fatal: '/' does not appear to be a git repository
fatal: Could not read from remote repository
Please make sure you have the correct access rights
and the repository exists.
I tried adding the folder name, ".git", foldername.git, everything, and I get the same error.
Where am I having the issue? Thank you beforehand.
P.S. I already tested the new default directory and it points right to the empty repository in the server, so it's working.
EDIT: I tried this:
$ git ls-remote user#host:.git
user#host's password:
$_
I got no output. Is that okay?
You're saying the git repository at your server is located at / (say, you should have a /.git directory). As that's probably not true, I'd suggest you to connect via ssh to the server and run pwd (or it's Windows equivalent) to found where your home directory is, and then get the relative path to your repository.
Say, if running pwd right after logging into the server gives you C:\users\my_user and your git repository is at C:\users\my_user\git\my_project, use ssh://user#server:git/my_project as the URL. The : means a relative path from your home directory.
Also you can use an absolute path, as in ssh://user#server/c/users/my_user/git/my_project, or however Windows decides to name your C: partition :)
As you use ssh transport, your syntax tries to access the root of your Copssh installation, Example: if you installed Copssh at c:\copssh, then your root (/) is the same directory.
Your command git ls-remote ssh://user#server/ tries to access that directory.
Try something like
git ls-remote ssh://user#server/home/user* (c:\copssh\home\user) or
git ls-remote ssh://user#server/cygdrive/d/mygit if your repository is at d:\mygit)
If you all want to create a Windows based Git repository, you may consider to stick with Gitwin which has a fully functional free edition. It is Git on Cygwin though and Disclaimer: I'm the developer.

Using SSH Keys on different Mac

I have GIT and my repos setup on a MacBook Air. I'm trying to clone the repo on my iMac. My understanding was that I needed to copy my key over from the /.ssh folder on the MBA to the same folder iMac.
However, when I try and clone the repo on the iMac, I get the following error:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
I've done a little research already and have verified that...
I have the latest version of GIT and that my user.name and user.email variables are configured correctly. (New Mac - new SSH keys for github?)
the ownership & permissions on the .gitconfig file and parent folder are r/w and owned by my user. (Trouble setting up Tower with my GitHub Account - error: could not lock config file)
my $HOME environment variable points to my users working directory. (Trouble setting up git with my GitHub Account error: could not lock config file)
At this point, I am all out of ideas and could really use some advice.
Suggestions?
Thanks!
Can't believe I found the solution right after I got done posting this, but for those who are copying keys to new machines, you have to let SSH know the keys are there. See this answer for details:
https://stackoverflow.com/a/12100237/337824

Setting up a Git repository under Review-Board on Windows Server 2003

I need some help.
I have a Windows Server 2003 computer that I'm setting up with Git and Review-Board.
My Git repositories are managed by Gitolite. The setup is successful and everything is working fine (tested with multiple workstations).
The Review-Board site has installed successfully and is hosted under Apache 2.2. This is also working fine in itself (the website is accessible and responds for workstations), except the part where I'm trying to link Git repositories to Review-Board.
Most tutorials (example: http://ericholscher.com/blog/2011/jan/24/using-reviewboard-git/) provide good details on how to setup a Git repository under Review-Board, except that they refer to Linux/Unix systems, and I am running Windows Server 2003.
My Gitolite repositories are stored under D:\Repositories\Git
Example: D:\Repositories\Git\sdu-test\.git
My understanding is that Review-Board needs a local clone of the repository(ies). Therefore, I created a directory named LocalClones and I cloned my repository.
Example: D:\Repositories\LocalClones\[I cloned sdu-test.git here]
Command used (from LocalClones directory): git clone ../Git/sdu-test.git(the clone was successful)
Now, in Review-Board, I'm trying to declare my sdu-test repository.
Name is 'sdu-test'
Hosting type is 'Custom'
Repository type is 'Git'
Path is 'D:\Repository\LocalClones\sdu-test' (I have also tried with 'sdu-test.git', and 'sdu-test/.git')
Mirror path is 'ssh://git#localhost/sdu-test' (I have also tried simply 'git#localhost:sdu-test', and no mirror path at all)
When I click Save, I get the following error: (11001, 'getaddrinfo failed'). I have no idea what to do about that.
If I try to change the path to a Unix-style path ('/D/Repository/LocalClones/sdu-test'), I get a different error message: Permission denied accessing the local Git repository '/D/Repository/LocalClones/sdu-test'. With a Unix-style path, I could even write a directory path that doesn't exist ('/I/Dont/Exist') and the same permission denied error is returned (the path in the error message does reflect the change though).
Can anyone help me out and tell me how to declare my local Git repository in Review-Board under Windows?
Thank you very much!
** UPDATE ** thank you Tamagochi and VonC for your answers, but unfortunately they're not working for me. Even after fixing the git.py file, I still get the Permission denied accessing the local Git repository '/D/Repository/LocalClones/sdu-test' error message.
There appears to be a bug in ReviewBoard 1.5.5 that causes this error. You can resolve this problem in either of two ways:
Move your repositories to drive C.
Edit \reviewboard\scmtools\git.py file, and replace the following line:
self.git_dir = url_parts[2]
with:
self.git_dir = url_parts[1] + url_parts[2]
Then use the following path: file://D:/Repository/LocalClones/sdu-test
I don't have any experience with ReviewBoard, but from what I can gather (from your link):
you do need to put the full path up to the .git directory of the local clone.
you should make your local clone through an url-based address. If the local file protocol is to be used, you should try with file///D/Repository/LocalClones/sdu-test.
git#localhost:sdu-test would only work if you have a git daemon running.
ssh://git#localhost/sdu-test would only work if you have a ssh daemon running.

Cannot get git extensions to push something to github SSH problems

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.
Things to check for:
Presence of HOME environment variable.
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
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...
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.
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).
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.
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.
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?

Resources