从初始本地仓库到提交至码云远程仓库
2018-11-09 本文已影响98人
HLE
一:本地操作
1.在本地磁盘建立本地项目根目录(空文件夹)

2.将本地项目目录初始化为本地代码仓库:
a: 在项目根目录下打开git bash命令工具;
b:输入git init ,来初始化

执行完git init命令后,在项目根目录中就会出现一个.git的文件夹(没有显示可能是你的电脑设置了隐藏文件夹)
3.配置git config
使用输入下面的两行命令,来配置全局用户信息:
a: git config --global user.name "你的用户名"
b: git config --global user.email "你的邮箱地址" (注;邮箱地址可以不是自己的真实邮箱,可以是任意的,但是要记住)

4.此时,本地仓库的初始化和用户配置就完成了,就可以在项目目录下写代码了
新建一个readme.txt文件作为要提交的练习文档。

5.将项目文件提交到暂存区
使用git add . (最后的圆点表示文件夹下的所有项目文件) 或使用git add readme.txt添加具体的文件

6.提交到本地仓库
使用git commit -m "本次提交的描述文本"

7.查看提交记录
使用git log 或者git log --oneline

到这里,本地的操作就全部完成了,现在要开始在码云上创建项目了设置密钥了;
二.在码云上创建项目,设置ssh
1.创建项目(没注册的注册一个码云账号)


2.码云中的代码仓库就创建完成了。现在设置ssh
1.准备工作



2.生成公钥
在git bash命令工具中输入指令:
ssh-keygen -t rsa -C "你在config中设置的user.email"
现在,去c盘-->user(用户)-->administer-->.ssh文件夹 下第二个文件用编辑器打开就是项目公钥,复制

3.填写公钥

三.连接远程仓库,上传代码
1.打开步骤一创建的代码仓库

2.执行命令
git remote add origin ........
git push -u origin master

3.再在本地项目中创建一个新的文件夹来测试一下

执行命令,提交到远程仓库

4.结果:
新提交的文件上传成功
