关于git:使用git在gitlab拉取代码的方法

2次阅读

共计 988 个字符,预计需要花费 3 分钟才能阅读完成。

须要在服务器上部署新写的我的项目,须要从新填写一次 gitlab 的配置信息。因为距离太久了,对于配置曾经不太记得了,所以在这里记录下,不便当前用到时,能够迅速找回。

可参考 Github 的官网文档

1. 生成 SSH key

在服务器的终端输出命令(替换下方命令的邮箱地址,填写 github/gitlab 注册邮箱地址):

ssh-keygen -t rsa -C "your_email@example.com"

这将创立以所提供的电子邮件地址为标签的新 SSH 密钥。

Generating public/private rsa key pair.

提醒您“Enter a file in which to save the key(输出要保留密钥的文件)”时,按 Enter 键。这将承受默认文件地位。如果须要自定义地位或者自定义名称,请输出所在的门路残缺名称,如:/Users/you/.ssh/id_rsa_gitlab

Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]

在提醒时输出平安明码。更多信息请参阅“应用 SSH 密钥明码”。

Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]

2. 将生成 SSH key 加载到 github/gitlab

将上述步骤生成的 ssh key 复制进去

# 查看
cat /Users/you/.ssh/id_rsa_gitlab.pub
# 复制
选中,按下 ctrl + C 即可 

接下来,关上并登录你的 github/gitlab,进入到 Settings -> SSH Keys,将复制到的 key 填写到上述输入框,可更改 key 的 Title,便于辨认这个 key 用在哪个中央。实现操作后,即为胜利增加 Key。

3. 本地操作

实现增加 key 后,临时还没方法应用,须要在本地进行测试连贯。

# 将 SSH 私钥增加到 ssh-agent 并将明码存储在密钥链中。ssh-add /Users/you/.ssh/id_rsa_gitlab

ssh -T -v git@github.com(也能够是公司部署的 git 地址)

呈现以下文案示意连贯胜利。接下来即可应用 git clone 命令了。

Welcome to Github, @your_email!
正文完
 0