jt.vervliet
jt.vervliet

Reputation: 171

How to use Git with two differents repositories with and without ssh authentification?

I have got a problem:

I have to work with to projects :

All is fine, when I'm working with the gitlab's projects, but when I'm trying to pull, push, fetch projects not on gitlab server: git bash returns :

Enter passphrase for key '/c/Users/my_user/.ssh/id_rsa':

But I don't need any ssh authentication !

When I run git remote -v for the gitlab project, git bash returns :

$ git remote -v

origin http://xxxx/yyyy-tools/yyyy-demat-purge.git (fetch)

origin http://xxxx/yyyy-tools/yyyy-demat-purge.git (push)

When I run git remote -v for the other repo (not on gitlab) it returns :

$ git remote -v

origin git@myIp:/repository/yyyy/yyyy-order-parent.git (fetch)

origin git@myIp:/repository/yyyy/yyyy-order-parent.git (push)

So I think that it's a not a remote configuration problem...

When I try to bypass the question of the ssh authentication to access to the repository not on gitlab, git bash returns :

$ git remote -v

origin git@ip:/repository/yyyy/yyyy-order-parent.git (fetch)

origin git@ip:/repository/yyyy/yyyy-order-parent.git (push)

$ git fetch origin

Enter passphrase for key '/c/Users/user/.ssh/id_rsa':

git@ip's password:

GitLab: The project you were looking for could not be found. fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

Here is the content of the non-gitlab ~/.ssh/config file

Host DEV_XX1

HostName DEV_XX1

User gitUser

IdentityFile /home/hostUser/.ssh/id_rsa

IdentitiesOnly yes

Host myIp

User hostUser

ProxyCommand ssh deploy@myIp -W %h:%p

How can I resolve this problem ? I think that it can exist a configuration solution, but which one?

Thank you !

Upvotes: 1

Views: 260

Answers (1)

Klaus
Klaus

Reputation: 461

The problem is that, in your second project, the remote url might be set to a ssh url,something like git@ip/.... (run the command: "git config -l" to see, pay attention to "remote.origin.url=")

You need to edit the url to the one that uses http or some other protocol provided by your git server. Use the follow command to edit:

git remote set-url origin https://yourusername@servername/username/project.git

In summary, there're two ways to work this out. Firstly, use "remote set-url" command as my answer above, to change your url to http. Secondly, use ssh authentication. You neet to generate a public/private key pair, then store the public key to git server (if your git server support it). Finally, create a ~/.ssh/config file with following content:

Host hostname host_ip 
HostName host_ip 
IdentityFile ~/.ssh/privatekey
User yourusername

This way, the authentication will be automatically taken care of

Upvotes: 3

Related Questions