一、git客户端(本地仓库)的一些操作
1.设置账户(需要和github账户设置一致)
git config --global user.name xxx
git config --global user.emailxxx@foxmail.com
2.查看设置
git config --list
user.name=xxx
user.email=xxx@foxmail.com
3.通过 git init 创建git本地仓库(先创建文件夹,在文件夹内部)


4.通过git add . 添加代码到本地仓库

5.通过git status 查看添加的文件,如下图

6.用git commit把项目提交到仓库

二.上传GitHub
由于本地Git仓库和Github仓库之间的传输是通过SSH加密的,所以连接时需要设置一下:
1.创建SSH KEY。先看一下你C盘用户目录下有没有.ssh目录,有的话看下里面有没有id_rsa和id_rsa.pub这两个文件,有就跳到下一步,没有就通过下面命令创建
$ ssh-keygen -t rsa -C"youremail@example.com"
然后一路回车。这时你就会在用户下的.ssh目录里找到id_rsa和id_rsa.pub这两个文件

2.在github上申请一个账号
3在Github,找到右上角的图标,打开点进里面的Settings,再选中里面的SSH and GPG KEYS,点击右上角的New SSH key,然后Title里面随便填,再把刚才id_rsa.pub里面的内容复制到Title下面的Key内容框里面,最后点击Add SSH key,这样就完成了SSH Key的加密。具体步骤如下:




4.在GitHub上面创建一个新仓库,在右上角找到你的小头像旁边的加号 点击下拉图标,找到新建仓库 如下图

5.进入创建仓库页面,如下图,红色箭头处表示你所建立的项目名字,绿色箭头处表示项目的一些详细描述可以选择填补填写,在往下面的Public表示公开, 别人可见 Private表示私有,别人看不到; 最后点击Create repository创建


6.在Github上创建好Git仓库之后我们就可以和本地仓库进行关联了,根据创建好的Git仓库页面的提示,可以在本地TEST仓库的命令行输入:git remote add origin https://github.com/rongice/textCode.git
注意origin后面加的是你Github上创建好的仓库的地址。如图


7.关联好之后我们就可以把本地库的所有内容推送到远程仓库(也就是Github)上了,通过:git push -u origin master
由于新建的远程仓库是空的,所以要加上-u这个参数,等远程仓库里面有了内容之后,下次再从本地库上传内容的时候只需下面这样就可以了 git push origin master

8. 这时候你再重新刷新你的Github页面进入刚才新建的那个仓库里面就会发现项目已经成功上传了:

网友评论