Loading

git使用

1. git使用

git使用

1.1. 如何将企业中仓库代码拉取到本地

git从gitlab拉取最新的代码到本地
为GitLab帐号添加SSH keys并连接GitLab
使用Git拉取GitLab上的项目

  1. Git下载地址
    https://www.git-scm.com/download/win

  2. 安装Git
    (安装步骤参考https://www.cnblogs.com/xwgcxk/p/9209237.html)

  3. 从管理员手中拿到用户名、邮箱、密码
    假设用户名为: itcats_cn
    邮箱为itcats_cn@itcats.cn
    密码为12345678

  4. 初始化git信息(在右键Git Bash输入以下命令)

    1. git config --global user.name 'itcats_cn'
    2. git config --global user.email 'itcats_cn@itcats.cn'
  5. 检查并且配置公钥(SSH)

    1. 检查ssh的方法
      • 查看本机 ssh 公钥,生成公钥
      • 检查是否存在id_rsa.pub文件,若已经存在id_rsa.pub文件,则表示存在
      • 可以通过如下命令进行查找公钥:
        • 打开你的 git bash 窗口
        • 进入 .ssh 目录:cd ~/.ssh
        • 找到 id_rsa.pub 文件:ls
        • 查看公钥:cat id_rsa.pub 或者 vim id_rsa.pub
          img
    2. 若不存在这个文件,使用命令"ssh-keygen -t rsa -b 4096 -C "your_email@example.com" ## your_email@example.com是gitlab的账号。(plus:直接按Enter即可,密码可输入可不输入)
    3. 查询全局的配置 git config --list
  6. 复制公钥到gitlab
    img

  7. 使用git clone xxxxxxx.git 从远程仓库拉取代码

1.2. 本地代码有变更如何提交到仓库

  1. 本地的代码项目,如何上传到git仓库中
    git config --global user.name "xxxxx"
    git config --global user.email "xxxxxxxx@xxxxx.com"
posted @ 2025-06-25 11:55  system_T  阅读(40)  评论(0)    收藏  举报