配置ssh
1、安装git
*这一步没有做,服务器自带。但是我看有些博客说最好更新下最新的git
安装成功后输入git如下图:
(base) [isp001@172.18.32.131 video_stabilization]$ git
usage: git [--version] [--help] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
配置用户邮箱和用户名
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
这个一定要配置,不然无法clone 远程仓库.
2、安装SSH密钥
Git 服务器都使用 SSH 公钥进行认证, 生成ssh密钥的命令如下,密钥保存位置选择默认目录就行,一直Enter。 生成的密钥文件在:~/.ssh/id_rsa.pub 里
(base) [isp001@172.18.32.131 ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/mnt/data/isp001/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /mnt/data/isp001/.ssh/id_rsa.
Your public key has been saved in /mnt/data/isp001/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:UNemaAhcxPyZtAhqT1Bmp7dS+JvuMViIQltwTcxCsno isp001@centos
The key's randomart image is:
+---[RSA 2048]----+
| o.=O*+ . .. |
| *++Bo... o |
| o ++o+= = o |
|o =..=ooB . |
|ooEoo +.S |
| o .+ o |
| . = |
| . o |
| .o |
+----[SHA256]-----+
使用cat查看生成的公钥
(base) [isp001@172.18.32.131 ~]$ cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDhOvk5ulu2cUNiyYQLOQpBajmgwrHpfo9PQsREWqq2I6AspMTUigbgTCur4EdUk/6AO0n6W2Rev4zLbPZIe8yoxYIgGUauJgaP7fmPG1sVPNGyZvZwracCFDVN49HjTp3dygN5eRtx2ECyusvM7DEp9p8r5uNvpgReTAvP7PqyuC5Lqk26vpdxFwrsGbFo4AOI3R8fTUEHg9Jch+Yu4wQ2uzxp4URiOazWsXB2eHH84ioX2tLBCjobdsBYFAh4vecrt/MORhSak/vAD5cFNO/ffOxti6tywnxZ9i2TvIUyPTx4wMlrMjxgG0qaB8ELYIxlpJ0ZS8tZp5JzuSDtOQJ5 isp001@centos
注意: 上面生成的公钥需要复制到git hub远程仓库的SSH keys中,在下面会介绍如何复制。
3、公钥使用
将生成的SSH密钥复制到Setting->SSH and GPG keys->SSH keys里
输入下面的命令检查是否成功配置ssh,下图表示成功。
(base) [isp001@172.18.32.131 ~]$ ssh -T git@github.com
The authenticity of host 'github.com (20.205.243.166)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
ECDSA key fingerprint is MD5:7b:99:81:1e:4c:91:a5:0d:5a:2e:2e:80:13:3f:24:ca.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added 'github.com,20.205.243.166' (ECDSA) to the list of known hosts.
Hi ysj-xuanyuan! You've successfully authenticated, but GitHub does not provide shell access.
github使用
4. 使用git clone从远程仓库下载文件
使用git clone命令,下载远程仓库文件到本地。(使用ssh链接进行clone)
(base) [isp001@172.18.32.131 code]$ git clone git@github.com:lchia/video_stabilization.git
Cloning into 'video_stabilization'...
remote: Enumerating objects: 307, done.
remote: Counting objects: 100% (307/307), done.
remote: Compressing objects: 100% (255/255), done.
remote: Total 307 (delta 42), reused 307 (delta 42), pack-reused 0
Receiving objects: 100% (307/307), 18.99 MiB | 4.42 MiB/s, done.
Resolving deltas: 100% (42/42), done.
5、本地可以更新文件并push到远程仓库
vim README_VStab.md
git add README_VStab.md
git commit -a -m 'first_push'
git push origin main
注意之前的教程中使用git push origin master ,但是现在master改成main
6、创建新的branch
查看当前分支,带 * 的表示当前分支
git branch
创建新的branch
git branch 分支名字
切换到新分支
git checkout 分支名字
在新分支创建文件
vim XXX
git add XXX
gti commit -a -m "同步文件做的注释"
git push origin 分支名字
7、删除本地分支
git branch -d 删除的分支名字
8、合并分支
建议轻易别用!!!!!!!
1、进入要合并的分支main
git checkout main
2、更新本地的分支仓库
git pull
maser中合并了相应分支的代码
3、使用merge合并开发分支
git merge 分支名
搞定!!!
git中push和pull的差别:https://www.icode9.com/content-4-370841.html。
一般用push就够了
git push 命用于从将本地的分支版本上传到远程并合并。 只有一个分支才能这么省略着使用
git pull 命令用于从远程获取代码并合并本地的版本。
git pull 其实就是 git fetch 和 git merge FETCH_HEAD 的简写。
|