把本地项目推送到github的命令

来源:互联网 发布:python 接收上传图片 编辑:程序博客网 时间:2024/06/06 01:55

首先你要登录github新建一个仓库,记录下这个仓库的地址,地址一般是: https://github.com/username/repositoryname.git/

仓库建立完毕后,这时候就需要用我们之前安装的git命令来将本地的代码推送到github上了。如果你仅为了展示自己的前端页面,那么只要掌握如下命令即可(不熟悉git命令的可以参考git - 简易指南):

(1)打开你的目录

cd demo 

(2)初始化版本库,用于生成git文件

git init

(3)将所有文件添加到缓存区

git add * 

(4)提交当前工作空间的修改内容

git commit -m "first commit"

(5)将仓库连接到远程服务器

git remote add origin <server>(就是上面你仓库的地址) 

(6)将改动推送到所添加的服务器上

git push -u origin master 

在推送的时候我出现了错误如下:

warning: redirecting to https://github.com/kellywang1314/dabai.git/To http://github.com/kellywang1314/dabai.git ! [rejected]        master -> master (fetch first)error: failed to push some refs to 'http://github.com/kellywang1314/dabai.git'hint: Updates were rejected because the remote contains work that you dohint: not have locally. This is usually caused by another repository pushinghint: to the same ref. You may want to first integrate the remote changeshint: (e.g., 'git pull ...') before pushing again.hint: See the 'Note about fast-forwards' in 'git push --help' for details.

查了一下错误的原因是github中的README.md文件不在本地代码目录中。所以我们把上面第六步分成两步:

git pull --rebase origin master:进行代码合并git  push -u origin master 
原创粉丝点击