1.gitee上新建代码仓库

将网址进行记录
https://gitee.com/cui-chengjie/test
随后生成秘钥,公钥在gitee上进行添加

2.在Git bash上进行操作
进入git bash

用如下命令获取秘钥,其中公钥在gitee上添加,邮箱为注册gitee所用邮箱
ssh-keygen -t rsa -C "youremail@youremail.com"
查看公钥使用如下命令
cat ~/.ssh/id_rsa.pub

在添加完成后,在终端输入
#Gitee
$ ssh -T git@gitee.com
#GitHub
$ ssh -T git@github.com

如上显示已经成功连接
开始设置基本信息
git是分布式的,需要设置自己的用户名和邮箱,用户名尽量保持一致,邮箱必须是注册时所使用的邮箱。
$ git config --global user.name "yourname"
$ git config --global user.email "youremail@youremail.com"

随后对本地库进行初始化
将远程库克隆到本地,或者在本地初始化项目后,再进行云端绑定
克隆
#Gitee
$ git clone https://gitee.com/yourname/repository
#Github
$ git clone https://github.com/yourname/repository.git
#yourname 您在码云或github注册的用户名
#repository 您创建的远程仓库名称

远程仓库已经克隆到本地

对本地进行初始化,并更新到远程仓库
#Gitee
$ cd d:/test //首先在文件系统中创建一个项目文件夹,然后在Git中 cd 到这个工程目录
$ git init //初始化本地项目
$ git remote add origin <远程仓库地址> //绑定远程仓库
#注:地址形式为 https://gitee.com/yourname/test.git 或 git@gitee.com:yourname/test.git
#Github
$ cd d:/test
$ git init
$ git remote add origin <远程仓库地址>
#注:地址形式为 https://github.com/yourname/test.git
git add . //指定更新内容 . 表示全部更新,test.txt 表示更新指定文件
git commit -m "一些注释说明" //添加更新说明
git push origin master //执行更新操作

上图中第一次推送失败,是由于没有默认的README.MD文件,使用git pull --rebase origin master即可解决问题
随后在gitee上查看
gitee与github使用流程基本相同,仅代码库地址略有不同
如果提示是由于密码错误造成的推送失败则
控制面板-用户账户-管理windows凭据 对如下进行修改


对用户名和密码进行正确的填写
网友评论