Cuando utilizamos Git y tenemos diferentes proyectos cada uno con diferente proveedor podemos configurar/utilizar una llave en específico para cada proveedor.
En este caso de uso vamos a configurar dos llaves Git una para Gitlab y otra para Bitbucket
Creamos las llaves
- Creamos la llave para Gitlab
$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (~/user/.ssh/id_rsa): ~/user/.ssh/gitlab-key - Creamos la llave para Bitbucket
$ ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (~/user/.ssh/id_rsa): ~/user/.ssh/gitlab-key
Configuramos las llaves
- Configuramos las llaves en el archivo
~/.ssh/configHost gitlab HostName gitlab.com User git IdentityFile ~/.ssh/gitlab-key IdentitiesOnly yes Host bitbucket HostName bitbucket.org User git IdentityFile ~/.ssh/bitbucket-key IdentitiesOnly yes
Utilizando la configuración
Ahora ya podemos utilizar los comandos para clonar y hacer push
-
Clonar repositorios
$ git clone git@gitlab:my-page.git$ git clone git@bitbucket:project-one/my-blog.git -
Agregamos las directivas a los repositorios
git remote add gitlab git@gitlab:awesomeproject.gitgit remote add bitbucket git@bitbucket:project-one/my-blog.git -
Subimos cambios
git push gitlab maingit push bitbucket master