赞
踩
下载(Ubuntu)
sudo apt update
sudo apt install git
验证下载
git --version
配置
git config --global user.name "Your Name"
git config --global user.email "email@domain.com"
验证配置
git config --list #正常则会打印出你的用户名和邮箱
生成密钥
ssh-keygen -t rsa -C "email@domain.com"
如果回车后打印如下:
Generating public/private rsa key pair.
Enter file in which to save the key (/home/username/.ssh/id_rsa):
这里是在设置存储地址,直接按回车,会出现以下两种情况
Enter passphrase (empty for no passphrase):
按回车
Enter same passphrase again:
继续按回车,打印出密钥的随机图像则表示成功
/home/username/.ssh/id_rsa already exists.
Overwrite (y/n)?
这说明已经设置了存储地址,输入“y”覆盖
Enter same passphrase again:
继续按回车,打印出密钥的随机图像则表示成功
查看公钥
cat ~/.ssh/id_rsa.pub
复制公钥到gitee
测试是否和gitee连通
ssh -T git@gitee.com
打印如下表示成功
The authenticity of host 'gitee.com (212.64.63.190)' can't be established.
ECDSA key fingerprint is SHA256:FQGC9Kn/eye1W8icdBgrQp+KkGYoFgbVr17bmjey0Wc.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'gitee.com,212.64.63.190' (ECDSA) to the list of known hosts.
Hi username! You've successfully authenticated, but GITEE.COM does not provide shell access.
代码推送到远端仓库
初始化一个仓库
mkdir test_git/ && cd test_git/ git init
- 1
- 2
添加代码
touch main.cpp git add .
- 1
- 2
提交代码到仓库
git commit -m "Add a file which names main.cpp"
- 1
先在gitee上创建仓库:test_git
添加远程仓库地址(已经被添加过了则不用执行这一步)
git remote add origin https://gitee.com/username/test_git.git
- 1
推送到远程仓库的master分支
git push origin master
- 1
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。