zoukankan      html  css  js  c++  java
  • git使用

    配置ssh密钥

    分别对githubn和gitlab生成对应的密钥(默认情况下本地生成的秘钥位于/Users/用户名/.ssh/),并且配置git访问不同host时访问不同的密钥,

    1、 在gitbash中使用 ssh-keygen -t rsa -C "公司邮箱地址"-f ~/.ssh/gitlab_id_rsa 生成对应的gitlab密钥:gitlab_id_rsa 和 gitlab_id_rsa.pub
    2、 将gitlab公钥即 gitlab_id_rsa.pub 中的内容配置到公司的gitlab上
    3、 在gitbash中使用 ssh-keygen -t rsa -C "github地址" -f ~/.ssh/github_id_rsa 生成对应的github密钥:github_id_rsa 和 github_id_rsa.pub
    4、 将github公钥即 github_rsa.pub 中的内容配置到自己的github上

    配置config文件

    在密钥生成的地方添加一个config文件

    # gitlab
    Host gitlab
        HostName gitlab  #注意,这里填写的是公司gitlab的地址,比如world.taobao.com,不要后面的路径,
        User git
        IdentityFile ~/.ssh/gitlab_id_rsa
    # github
    Host github.com
        HostName github.com
        User git
        IdentityFile ~/.ssh/github_id_rsa

    测试

    在gitbash中使用 ssh -T git@HostName 进行测试,出现以下即为成功

    hello@TH201956259 MINGW64 ~/.ssh
    $ ssh -T git@gitlab.com
    Welcome to GitLab, hello!
    
    hello@TH201956259 MINGW64 ~/.ssh
    $ ssh -T git@github.com
    Hi hello! You've successfully authenticated, but GitHub does not provide shell access.

    配置仓库

    1. 用户级别配置
    因为公司的代码使用频率较高,所以我们将git配置文件的global(用户级别)设置为公司的gitlab账号,在gitlab仓库中使用如下命令:

    $ git config --global user.name 'catalinaLi' #公司账号名称
    $ git config --global user.email 'catalinaLi@companyName.com' #公司账号邮箱

    2. 仓库级别配置
    进入github仓库执行如下命令:

    $ git config --local user.name 'username' #github账号名称
    $ git config --local user.email 'username@gmail.com' #github账号邮箱

    之后我们github的代码都应该在这个仓库下拉取。

  • 相关阅读:
    ARPG手游实战练习(八)
    ARPG手游实战练习(七)
    ARPG手游实战练习(六)
    ARPG手游实战练习(五)
    ARPG手游实战练习(四)
    ARPG手游实战练习(三)
    C# Array类的Sort()方法
    C#继承讲解以及对象的创建
    单例模式
    愤怒的小鸟(练习版)
  • 原文地址:https://www.cnblogs.com/sunshinekevin/p/13941687.html
Copyright © 2011-2022 走看看