将本地nodejs服务器的代码提交到github
来源:互联网 发布:unity3d开发流程 编辑:程序博客网 时间:2024/06/05 16:34
将本地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”。
1. 编写README.md
README.md是markdown格式的,需要写上此代码仓库的用途以及用法,方便他人理解。
也可以在提交到github之后,再添加README.md也是可以的。
注:本文中代码仓库是指github中的repository。
2. 初始化代码仓库:git init
$ git init初始化空的 Git 仓库于 /cygdrive/d/git/nodejs/.git/
查看当前状态:
$ git status位于分支 master初始提交未跟踪的文件: (使用 "git add <文件>..." 以包含要提交的内容) README.md images/ index.js requestHandlers.js router.js server.js提交为空,但是存在尚未跟踪的文件(使用 "git add" 建立跟踪)
3. 添加文件到本地代码仓库: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.js
4. 提交到本地代码仓库:git commit
$ git commit -m "http server created by nodejs"[master(根提交) f536e1d] http server created by nodejs 7 files changed, 159 insertions(+) create mode 100755 README.md create mode 100755 images/abracadabra.jpg create mode 100755 images/view.jpg create mode 100755 index.js create mode 100755 requestHandlers.js create mode 100755 router.js create mode 100755 server.js
5. 在github中创建代码仓库
登陆自己的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
6. 将本地代码仓库与github的代码仓库(远程仓库)进行绑定:git remote add
$ git remote add origin https://github.com/galian123/nodejs_http_server
验证一下远程仓库是否绑定上,执行git remote -v
:
$ git remote -vorigin https://github.com/galian123/nodejs_http_server (fetch)origin https://github.com/galian123/nodejs_http_server (push)
7. 将本地代码仓库中的文件提交到github:git push
提交代码之前,先执行git pull origin master
,让远程代码仓库与本地代码仓库进行同步。
然后执行git push origin master
。
$ git push origin masterUsername for 'https://github.com':Password for 'https://[my_github_username]@github.com':对象计数中: 12, 完成.Delta compression using up to 4 threads.压缩对象中: 100% (12/12), 完成.写入对象中: 100% (12/12), 4.05 MiB | 142.00 KiB/s, 完成.Total 12 (delta 1), reused 0 (delta 0)remote: Resolving deltas: 100% (1/1), done.To https://github.com/galian123/nodejs_http_server 0e0d160..b4a6e17 master -> master
8. 刷新github中刚才创建的代码仓库
即,刷新https://github.com/galian123/nodejs_http_server
README.md的显示效果(部分):
可能出现的错误
! [rejected] master -> master (fetch first)error: 无法推送一些引用到 'https://github.com/galian123/nodejs_http_server'提示:更新被拒绝,因为远程仓库包含您本地尚不存在的提交。这通常是因为另外提示:一个仓库已向该引用进行了推送。再次推送前,您可能需要先整合远程变更提示:(如 'git pull ...')。提示:详见 'git push --help' 中的 'Note about fast-forwards' 小节。
或者
! [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
进行同步。
$ git pull origin master来自 https://github.com/galian123/nodejs_http_server * branch master -> FETCH_HEADMerge made by the 'recursive' strategy. LICENSE | 201 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 LICENSE
参考
(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
- 将本地nodejs服务器的代码提交到github
- git使用、将本地代码提交到github
- 将eclipse的代码提交到Github
- 提交本地代码到github
- 【git】:将本地代码提交到github远程仓库的简单命令行
- 将本地文档库提交到Github
- GitHub提交本地项目到服务器
- 从本地提交代码到github遇到的一些问题
- git 使用注意事:将本地仓库代码提交到远端(这里使用的是github)
- Git的使用,将本地代码git到GitHub
- 将Xcode的本地代码push到github仓库上
- 将本地的代码备份到GitHub上
- 将Xcode的本地代码push到github仓库上
- Git - 将本地的代码 push 到 GitHub
- 如何将本地的代码上传到github
- 如何将自己的本地代码上传到GitHub上
- 将代码提交到github(笔记)
- git将代码提交到github
- 快速直接解决AndroidStudio导入项目中的gradle问题
- Android属性动画(PropertyAnimation)(下)
- npm模块之opn使用教程(译)
- 官方录音播放demo
- 带参数的装饰器
- 将本地nodejs服务器的代码提交到github
- Oracle 11g服务详细介绍及哪些服务是必须开启的
- C++11 并发指南六(atomic 类型详解一 atomic_flag 介绍)
- C++11 并发指南五(std::condition_variable 详解)
- 167. Two Sum II
- 第三方支付回调地址代理转发
- 大三下学期了...
- Ubuntu16.04+Cuda8.0+Caffe+ Opencv3.2+Matlab2015b的配置、安装与编译(三)
- C++11 并发指南六( <atomic> 类型详解二 std::atomic )