将本地nodejs服务器的代码提交到github
本文中所提交的代码的执行效果,请参考:http://blog.csdn.net/u013553529/article/details/57646352
最终提交到github的URL为:https://github.com/galian123/nodejs_http_server 可以通过git clone https://github.com/galian123/nodejs_http_server
获取到。 或者,直接打开https://github.com/galian123/nodejs_http_server,点击页面中中的“Clone or download”,然后点击“Download Zip”。
README.md是markdown格式的,需要写上此代码仓库的用途以及用法,方便他人理解。
也可以在提交到github之后,再添加README.md也是可以的。
注:本文中代码仓库是指github中的repository。
git init
查看当前状态:
$ git status位于分支 master初始提交未跟踪的文件: (使用 "git add <文件>..." 以包含要提交的内容) README.md images/ index.js requestHandlers.js router.js server.js提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪)git add
查看当前状态:
$ git status位于分支 master初始提交要提交的变更: (使用 "git rm --cached <文件>..." 以取消暂存) 新文件: README.md 新文件: images/abracadabra.jpg 新文件: images/view.jpg 新文件: index.js 新文件: requestHandlers.js 新文件: router.js 新文件: server.jsgit commit
登陆自己的github,例如我的github:https://github.com/galian123
点击右上角的加号,点击“New repository”,如图:
设置“Repository name”,我起的仓库名为nodejs_http_server
。 添加“Description”,这是可选的,方便理解,例如“用nodejs搭建简易的HTTP服务器”。 不要勾选“Initialize this repository with a README”,因为之前我已经添加了README.md文件。如果之前没有事先写好README.md,则此时可以勾选“Initialize this repository with a README”,代码仓库创建完成之后,再编写README.md。
“Add .gitignore”,设置gitignore的类型。注意,如果你要导入github的是某个工程目录,例如Android PRoject、C++ project,那么,需要选择.gitignore,目的是防止不必要的文件传到github中。
“Add a license”,选择一个开源协议。
然后点击“Create repository”。
创建完代码仓库的样子,如图: 代码仓库的URL为:https://github.com/galian123/nodejs_http_server
git remote add
验证一下远程仓库是否绑定上,执行git remote -v
:
git push
提交代码之前,先执行git pull origin master
,让远程代码仓库与本地代码仓库进行同步。 然后执行git push origin master
。
即,刷新https://github.com/galian123/nodejs_http_server
README.md的显示效果(部分):
或者
! [rejected] master -> master (non-fast-forward)error: 无法推送一些引用到 'https://github.com/galian123/nodejs_http_server'提示:更新被拒绝,因为您当前分支的最新提交落后于其对应的远程分支。提示:再次推送前,先与远程变更合并(如 'git pull ...')。详见提示:'git push --help' 中的 'Note about fast-forwards' 小节。原因:本地仓库没有与远程仓库同步。 解决方法:执行git pull origin master
进行同步。
(1)https://help.github.com/articles/adding-an-existing-project-to-github-using-the-command-line/
(2)用nodejs搭建简易的HTTP服务器: http://blog.csdn.net/u013553529/article/details/57646352
新闻热点
疑难解答