注册帐户以及建立仓库
要想使用github第一步固然是注册github帐号了。以后就能够建立仓库了(免费用户只能建公共仓库),Create a New Repository,填好名称后Create,以后会出现一些仓库的配置信息,这也是一个git的简单教程。步骤以下:
html
打开https://github.com 直接在首页上注册
git
点按钮注册成功以后,在页面上方用户菜单上选择 “+”->New repository 建立一个新的仓库
github
为仓库取一个名字,点击建立仓库按钮 你将成功建立一个仓库
shell
配置Git
咱们先在电脑硬盘里找一块地方存放本地仓库,好比咱们把本地仓库创建在C:\MyRepository\1ke_test文件夹下ide
进入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.
解决方法:
一、再次输入如上命令,在命令以后加一个空格,回车
二、若是仍是不行,则执行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 ....
而后把文件复制到出现的文件夹