注册账户以及创建仓库
要想使用github第一步当然是注册github账号了。之后就可以创建仓库了(免费用户只能建公共仓库),Create a New Repository,填好名称后Create,之后会出现一些仓库的配置信息,这也是一个git的简单教程。步骤如下:
打开https://github.com 直接在首页上注册

点按钮注册成功之后,在页面上方用户菜单上选择 “+”->New repository 创建一个新的仓库

为仓库取一个名字,点击创建仓库按钮 你将成功创建一个仓库

配置Git
我们先在电脑硬盘里找一块地方存放本地仓库,比如我们把本地仓库建立在C:\MyRepository\1ke_test文件夹下
进入1ke_test文件夹 鼠标右键操作如下步骤:
1)在本地仓库里右键选择Git Init Here,会多出来一个.git文件夹,这就表示本地git创建成功。右键Git Bash进入git命令行,截图效果如下:

为了保险起见,我们先执行git init命令
$ git init

为了把本地的仓库传到github,还需要配置ssh key。
2)在本地创建ssh key
$ ssh-keygen -t rsa -C "your_email@youremail.com"
后面的your_email@youremail.com改为你的邮箱。我的邮箱是lilu@1ke.co,也是在github上注册的那个邮箱:

直接点回车,说明会在默认文件id_rsa上生成ssh key。
然后系统要求输入密码,直接按回车表示不设密码

重复密码时也是直接回车,之后提示你shh key已经生成成功。

然后我们进入提示的地址下查看ssh key文件。 我的电脑的地址是C:\Users\lilu\.ssh ,其中lilu是我的电脑的名称

打开id_rsa.pub,复制里面的key。里面的key是一对看不懂的字符数字组合,不用管它,直接复制。
回到github网站,进入Account Settings,左边选择SSH Keys,Add SSH Key,

title随便填,粘贴key。

3)验证是否成功,在git bash下输入
$ ssh -T git@github.com
回车就会看到:You’ve successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上github。

4)接下来我们要做的就是把本地仓库传到github上去,在此之前还需要设置username和email,因为github每次commit都会记录他们
$ git config --global user.name "your name"
$ git config --global user.email "your_email@youremail.com"
分别输入上述命令行 回车, 我的界面显示如下

5)进入要上传的仓库,右键git bash,添加远程地址
$ git remote add origin git@github.com:yourName/yourRepo.git
后面的yourName和yourRepo表示你再github的用户名和刚才新建的仓库,加完之后进入.git,打开config,这里会多出一个remote “origin”内容,这就是刚才添加的远程地址,也可以直接修改config来配置远程地址。

与github上的对应

提交上传
git init
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/jcyoungcj/test.git
git push -u origin master
1)接下来在本地仓库里添加一些文件,比如README
在本地新建一个README文件

然后在命令行输入一下命令
$ git add README
//若要上传整个文件 git add . (.之后还有一个空格 ,然后回车)
$ git commit -m "first commit"
我的执行界面如下

2)
git remote add origin https://github.com/jcyoungcj/BlackGlue.git
3)上传到github
$ git push -u origin master
git push命令会将本地仓库推送到远程服务器。
git pull命令则相反。
注:首次提交,先git pull下,修改完代码后,使用git status可以查看文件的差别,使用git add 添加要commit的文件。
大功告成,现在你知道如何将本地的项目提交到github上了。
4. github上新建resposity
5. 代码/文件上传
echo "# test" >> README.md
git init
git clone https://github.com/jcyoungcj/test.git
把文件复制到新出现的文件夹
git add README.md
git commit -m "first commit"
git remote add origin https://github.com/jcyoungcj/test.git
git push -u origin master
6. 上传另一份代码
在本地同一个代码库,上传至github上另一个工程
7. 常见问题
7.1
warning: LF will be replaced by CRLF in test.html.
The file will have its original line endings in your working directory.
解决方法:
1、再次输入如上命令,在命令之后加一个空格,回车
2、如果还是不行,则执行git config core.autocrlf false命令之后,再次执行add命令就可成功。
执行git add .(把所有内容添加到索引库中)
7.2
ssh: connect to host git.com port 22: Connection timed out
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
解决方法:
git clone ....
然后把文件复制到出现的文件夹