linux上使用git把代码push到gitee上
文章目录:
从git的远程服务器克隆、拉取
等操作,有两种方式:一种是HTTPS
,另一种是SSH
。SSH是更安全的选择。为gitee添加公钥,这样就可以用SSH拉取。
这里我们为gitee添加ssh公钥
,之后就可以安全的把代码推送push到gitee上
1 git添加ssh公钥
1、打开命令行,首先确保已经安装git
2、输入ssh-keygen -t rsa -C "你的邮箱地址"
三次回车之后就可以`生成密钥对``
(base) shl@zhihui-mint:~$ ssh-keygen -t rsa -C "shliang0603@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/home/shl/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/shl/.ssh/id_rsa.
Your public key has been saved in /home/shl/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:MBMpijXvVjrE9VghzPUp79uj3UCnccvneiEhGsjdMrQ shliang0603@gmail.com
The key's randomart image is:
+---[RSA 2048]----+
| oooo. |
| o . =o.o . |
| o = o=+= = |
|. . + o*.E o . |
| o o S * + + |
| = o . B o |
| . . . o + o|
| +.o o.|
| o.o.oo.|
+----[SHA256]-----+
(base) shl@zhihui-mint:~$
3、输入cat ~/.ssh/id_rsa.pub 查看你的 public key(公钥),结果如下:
(base) shl@zhihui-mint:~$ cat ~/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCv/APchA3aun5cmDUMU/C+hIiF+/TyGg9KCzl+62DKHJTBRD8n0BP8wQiVAGAZioBomdzPTZ7LJlv7cgCnmQPm5Rc/Jv5SQvFa+SqYAqjD44OfS5NRa+J/8T98Q0EpvdGZjUx+4fhiom6xuXxcRX/2de+SbMZTt22S4cHcf1a88+eNoJ+e4ulIJCYx96NwjpROCI9J5WYIFlLenUV47YDj4vxCG4JXNRmNrVAhKux/Bci3Gbc2QTyDYbSu7wS3ognCPIaP/f4l7zYchH07V75LGA1XFjO+P6a2NvqHz9OAqV8oin9t5RkaMpCSWr6QvlH3qYf9zMX3YfALDH4+4LjF shliang0603@gmail.com
(base) shl@zhihui-mint:~$
4、把途中从ssh-ras(包含)到最后面的邮箱地址(包含)复制一下。
5、打开码云 -> 设置 -> SSH公钥,就出现了下面的画面,把我们刚才复制的内容贴到提示区,最后点击左下角的确定即可。
6、输入 ssh -T git@gitee.com
,系统会提示你输入yes/no,输入yes
,如果出现:You've successfully authenticated, but GitHub does not provide shell access.
就表示成功了。
(base) shl@zhihui-mint:~$ ssh -T git@gitee.com
The authenticity of host 'gitee.com (180.97.125.228)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitee.com,180.97.125.228' (ECDSA) to the list of known hosts.
Hi shliang! You've successfully authenticated, but GITEE.COM does not provide shell access.
(base) shl@zhihui-mint:~$
7、最后记得配置用户密码
git config --global user.name "你的gitee账号"
git config --global user.email "你在gitee的邮箱地址"
设置完以上这些之后,再试试git push是否还需要提交账号密码
克隆的是不公开的代码,需要是项目的成员,然后输入gitee
的用户名
和密码
即可克隆
注意:
一般是把代码克隆下来,然后在其基础上进行修改,开发,最后再提交,否则可能会因为代码的版本不同报错,最后推代码的时候失败!
2 代码推送的流程
1、初始化一个仓库:git init
2、增加代码后,添加:git add .
3、提交代码到仓库:git commit -m "related_message"
4、添加远程仓库地址,这里就是添加在gitee上建立的仓库地址
git remote add origin https://gitee.com/shliang/test_git.git
5、把本地仓库推到远程存储仓库中
git push origin master
![](https://i-blog.csdnimg.cn/blog_migrate/2223b97e94968fdc5cfa7f8d76d0b744.png)
![](https://i-blog.csdnimg.cn/blog_migrate/e85abc2fbb453006e0af03455fb2ab0b.png)
♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠ ⊕ ♠