您的位置:首页 > 编程语言

git 终端 上传本地项目到github仓库

2016-12-15 10:52 330 查看
第一步:建立本地Git仓库

cd到你的本地项目根目录下,执行git命令

git
init

第二步:将本地项目工作区的所有文件添加到暂存区

git
add .

如果想添加项目中的指定文件,那就把.改为指定文件名即可
 

第三步:将暂存区的文件提交到本地仓库

git
commit -m ""

冒号里面写注释语句

第四步:在Github上创建自己的repository,创建如图所示

第五步:将本地仓库关联到Github上

  git remote add origin https://github.com/CSUDUC/ars
后面的URL地址就是我在第四步时复制的那个https地址

在这一步时如果出现错误:fatal:remote origin already exists

        那就先输入 git remote rm origin

再输入 git remote add origin https://github.com/FISHBALL1/DropList 就不会报错了。

第六步:最后一步,将代码由本地仓库上传到Github远程仓库

git push -u origin master

执行完之后如果无错误就上传成功了,需要提示的是这里的master是Github默认的分支,如果你本地的当前分支不是

master,就用git checkout master命令切换到master分支,如果你想用本地当前分支上传代码,则把第六步的命令

        里的master切换成你的当前分支名即可。

如果github上建的库里有readme文档,会出现如下错误:

 
error: failed to push some refs to 'https://github.com/CSUDUC/ars'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first integrate the remote changes
hint: (e.g., 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

可以通过如下命令进行代码合并【注:pull=fetch+merge]

git pull --rebase origin master

此时再执行语句 git push -u origin master即可完成代码上传到github

  上传成功界面
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: