DEV Community

Discussion on: Just Git like a pro

 
waterkip profile image
Wesley Schwengle

Yes, you are going to configure the GIT_SSH_COMMAND in your git config and if you correctly organise your projects you can use any forge by selecting the correct ssh key and you can even, with a little shell script do it within repo's depending on the remote.

Thread Thread
 
yokwejuste profile image
Steve Yonkeu

Sounds interesting as suggestion, will be best to avoid looping through the existing keys trying to find one.

But if you look closely, you will notice there is a change in the origin I use to clone the repos.

Take for example, to clone a personal repo I'll do the following:

# the gitconfig to be used

# for personal user
Host github.me

  HostName github.com

  User yokwejuste

  IdentityFile ~/.ssh/personal
Enter fullscreen mode Exit fullscreen mode

Then upon cloning the repo, I'll use:

# using this
git clone git@github.me:unstructuredstudio/zubhub.git

#instead of this
git clone git@github.com:unstructuredstudio/zubhub.git
Enter fullscreen mode Exit fullscreen mode

Having a close look at the ssh url, we can see a change from .com => .me

Thread Thread
 
waterkip profile image
Wesley Schwengle

Yes, as mentioned, you would use: sshCommand = -i ~/.ssh/id_client -o IdentityOnly=yes -F /dev/null:

The identityOnly=yes is only there to prevent ssh from looping over all your ssh-keys and potentially using a different ssh key. The -F /dev/null disables using your .ssh/config. You could also use a different SSH config for just the sshCommand, e.g. sshCommand = -F ~/.ssh/config-client and set the correct ssh options in that file.

I know what you are saying, but the problem is that you now need to change all the hostnames when cloning other remotes, upstream, yours and others depending on the size of your (project) team.

Thread Thread
 
yokwejuste profile image
Steve Yonkeu

Inputing the ssh identity file can be more effective in terms of performance at the end.

Thanks again for this.

Some comments have been hidden by the post's author - find out more