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

第一步:建立本地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

  上传成功界面


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值