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

  • 相关阅读:
    软件设计7个原则
    vue.js 样式绑定 font-size 问题
    实例理解scala 隐式转换(隐式值,隐式方法,隐式类)
    著名端口整理(常用服务的默认端总结)
    .NET Core Web API 实现大文件分片上传
    ngnix反向代理tomcat,ssl证书配置及自定义错误页面
    微信登录闪退
    gradle如何配置阿里云的中央仓库
    HashMap底层实现和原理
    关于Java中String类的hashCode方法
  • 原文地址:https://www.cnblogs.com/sunshinekevin/p/13941687.html
Copyright © 2011-2022 走看看