forked from xuxing409/blog-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
36 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
--- | ||
title: Git的配置和使用命令 | ||
date: 2022-04-26 16:22:15 | ||
updated: 2024-10-21 22:55:00 | ||
updated: 2025-02-12 15:40:00 | ||
categories: | ||
- 学习 | ||
tags: | ||
|
@@ -92,7 +92,7 @@ Git 支持两类钩子:**客户端钩子**和**服务器端钩子**。 | |
|
||
> https://git-scm.com/downloads | ||
## 2. 配置基本信息 | ||
## 2. 配置git信息 | ||
|
||
```shell | ||
git config --global user.name "01Petard" | ||
|
@@ -123,13 +123,19 @@ git config --list | |
|
||
## 3. 配置ssh key | ||
|
||
**RSA 类型密钥** | ||
|
||
```shell | ||
ssh-keygen -t rsa -C "[email protected]" | ||
ssh-keygen -t rsa -b 4096 -C "[email protected]" | ||
``` | ||
|
||
我创建过了就不创建了,之后需要创建一个访问这个密钥的密码,需要牢记。 | ||
**Ed25519 类型的密钥** | ||
|
||
```shell | ||
ssh-keygen -t ed25519 -b 4096 -C "[email protected]" | ||
``` | ||
|
||
这个密钥之后要放在github里的,所以这个文件不要误删了。 | ||
之后需要创建一个访问这个密钥的密码,如果不想每次提交都输密码就按回车,这个密钥之后要放在代码仓库里 | ||
|
||
 | ||
|
||
|
@@ -139,27 +145,39 @@ ssh-keygen -t rsa -C "[email protected]" | |
cat ~/.ssh/id_rsa.pub | ||
``` | ||
|
||
 | ||
**重要的来了**:本地创建多个ssh key,如果想既连github的项目,也想连公司的gitlab的项目,可以照着下面这样做 | ||
|
||
*补充一下,如果后期觉得push总是要输密码太麻烦,可以修改密码为空 | ||
|
||
 | ||
|
||
## 4. 将ssh key添加到github上 | ||
```shell | ||
ssh-keygen -t ed25519 -b 4096 -C "[email protected]" -f ~/.ssh/id_rsa_github | ||
``` | ||
|
||
### 4.1 点击Settings | ||
```shell | ||
ssh-keygen -t ed25519 -b 4096 -C "[email protected]" -f ~/.ssh/id_rsa_gitlab | ||
``` | ||
|
||
 | ||
```shell | ||
touch ~/.ssh/config | ||
``` | ||
|
||
### 4.2 点击New SSH key | ||
``` | ||
# GitHub Configuration | ||
Host github | ||
HostName github.com | ||
User git | ||
IdentityFile ~/.ssh/github_rsa | ||
 | ||
# GitLab Configuration | ||
Host gitlab | ||
HostName 10.0.0.177 | ||
User git | ||
IdentityFile ~/.ssh/id_rsa | ||
``` | ||
|
||
### 4.3 添加key | ||
## 4. 将ssh key添加到仓库中 | ||
|
||
<img src="https://cdn.jsdelivr.net/gh/01Petard/imageURL@main/img/webp-20220820172058826" alt="img" style="zoom:67%;" /> | ||
[点击Settings] -> [点击New SSH key] -> [添加key] | ||
|
||
### 4.5 验证链接 | ||
验证链接 | ||
|
||
```shell | ||
ssh -T [email protected] | ||
|