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的代码都应该在这个仓库下拉取。

  • 相关阅读:
    springloud系列搭建注册中心
    在生产环境下禁用swagger
    consul怎么在windows下安装
    linux上传与下载
    使用git将本地代码提交到码云上去
    springboot整合activemq(三)配置文件
    springboot整合activemq(二),消费均匀分析
    Python3学习之路~3.2 递归、函数式编程、高阶函数、匿名函数、嵌套函数
    Python3学习之路~3.1 函数基本语法及特性、返回值、参数、局部与全局变量
    Python3学习之路~2.9 字符编码与转码
  • 原文地址:https://www.cnblogs.com/sunshinekevin/p/13941687.html
Copyright © 2011-2022 走看看