一台电脑同时使用GitLab和GitHub仓库

    xiaoxiao2021-03-25  49

    到不同的国家要用不同的货币。同一台电脑 想要同时使用GitHub和GitLab,那么到GitHub家自然要用GitHub的钥匙才能开门,到GitLab家就要用GitLab家的钥匙。那么要做的有两点:

    1. 用Git生成两把钥匙;


    #GitHub的钥匙 # kingboy @ KingBoydeMacBook-Pro in ~/.ssh [7:50:33] ➜ ssh-keygen -t rsa -C "kingboy@163.com" Generating public/private rsa key pair. Enter file in which to save the key (/Users/kingboy/.ssh/id_rsa): /Users/kingboy/.ssh/github_id_rsa Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/kingboy/.ssh/github_id_rsa. Your public key has been saved in /Users/kingboy/.ssh/github_id_rsa.pub. The key fingerprint is: SHA256:h6UQw+e68ncp5sidqbBpRk3WKUR04VgdJpeIlqWnfrc kingboyworld@163.com The key's randomart image is: +---[RSA 2048]----+ | +=+*++o | | *Oo+o | | o++o.. | | ++++ | | +.oS . | | ..o . | | .. ... .. | | +=.+++o. | | ooo===oE | +----[SHA256]-----+ #gitlab ➜ ssh-keygen -t rsa -C "personal@company.com" Generating public/private rsa key pair. Enter file in which to save the key (/Users/kingboy/.ssh/id_rsa): /Users/kingboy/.ssh/gitlab_id_rsa Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /Users/kingboy/.ssh/gitlab_id_rsa. Your public key has been saved in /Users/kingboy/.ssh/gitlab_id_rsa.pub. The key fingerprint is: SHA256:h6UQw+e68ncp5sidqbBpRk3WKUR04VgdJpeIlqWnfrc personal@company.com The key's randomart image is: +---[RSA 2048]----+ | +=+*++o | | *Oo+o | | o++o.. | | ++++ | | +.oS . | | ..o . | | .. ... .. | | +=.+++o. | | ooo===oE | +----[SHA256]-----+

    注意:

    Enter file in which to save the key (/Users/kingboy/.ssh/id_rsa): /Users/kingboy/.ssh/github_id_rsa

    输入的是钥匙的位置和名称。github和gitlab是不同的。

    完成后会在~/.ssh/目录下生成以下文件:

    github_id_rsagithub_id_rsa.pub gitlab_id_rsa gitlab_id_rsa.pub

    将两个pub文件分别配置到github和gitlab的sshkey中

    2. 编写config文件,告诉本地git到不同的国家带不同的钥匙。

    例如:

    github地址:github.com gitlab地址:gitlab.max.com

    执行以下命令:

    cd ~/.ssh vim config

    config内容如下:(HostName根据自己实际需求来定)

    #gitlab Host gitlab HostName gitlab.*.com IdentityFile ~/.ssh/gitlab_id_rsa #github Host github HostName github.com IdentityFile ~/.ssh/github_id_rsa

    3. 配置仓库

    例如:

    github工作仓库:~/workspace/github gitlab工作仓库:~/workspace/gitlab #gitlab cd ~/workspace/gitlab git init git config --global user.name 'personal' git config --global user.email 'personal@company.com' #github cd ~/workspace/github git init git config --local user.name 'kingboy' git config --local user.email 'kingboy@163.com'

    接下来在两个目录下新建或者clone项目开发即可.

    转载请注明原文地址: https://ju.6miu.com/read-40798.html

    最新回复(0)