git使用教程1-本地代码上传到github

前言

不会使用github都不好意思说自己是码农,github作为一个开源的代码仓库管理平台,我们可以把自己的代码放到github上,分享给小伙伴,自己也能随时随地同步更新代码。

问题来了:为什么越来越多的小伙伴喜欢开源?答:因为我们可以免费下载到大神的源码啊!

 

一,注册Github账号

1.先注册一个账号,注册地址:https://github.com/

2.登录后,开始你的旅程

3.创建一个repository name,输入框随便取一个名字(不要用中文!!!)

4.点Create repository创建成功,界面如下

 

二、安装git

1.git是本地客户端管理代码的一个工具,下载地址:https://git-scm.com/download/win

2.下载到本地电脑后,一路傻瓜式安装Next->Next->-Next

3.安装完成后,本地随便建个文件夹,如github,在文件地址栏输入cmd

4.打开dos界面后输入git,看到如下界面说明安装成功

 

三、本地仓库

1.回到之前的github界面,下面有几个指令告诉我们如何把本地代码上传:

git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/yoyoketang/yoyoketang.git
git push -u origin master

2.在上面创建的github文件目录放需要上传的代码,然后安装上面的步骤开始操作

第一步:git init --建仓

第二步:git add  * --添加代码到本地仓库(*是代码添加全部更新的)

第三步:git commit -m "first commit"  --提交到本地缓存(“引号里面是说明提交了什么东西”)

(首次使用会提示:please tell me who you are)

如果看到上面的提示,就在cmd里面继续敲这两行:

>git config --global user.name "xxx@xxx.com(你的github邮箱)"   

>git config --global user.email "你的github用户名"(敲完之后,继续上面的commit这一步)

 

第四步:git remote add origin https://github.com/yoyoketang/yoyoketang.git  --提交到远程github上(后面的地址,就是之前配置的repository地址)

第五步:git push -u origin master  --push到master分支

3.代码上传成功后,如图所示

 

 

四、遇到问题与解决方案注意:初次使用的话,在输入上面指令过程中会遇到以下几个问题:

1.要是cmd窗口看到提示以下这两个信息

$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com

解决办法:按上面的提升,cmd窗口接着输入

>git config --global user.name "这里是你的github用户名"   

>git config --global user.email xxx@xxx.com(你的邮箱)

2.提交到远程时候,提示:

fatal: remote origin already exists.

解决办法:删除远程git仓库

>git remote rm origin

3.首次操作过程中需要登录就按提示输入账号名和密码

 

posted @ 2017-08-08 21:39  上海-悠悠  阅读(4882)  评论(0编辑  收藏  举报