使用Git版本控制工具将代码托管到GitHub上面

##使用Git版本控制工具将代码托管到GitHub上面

最近连续接触到了好几个项目,觉得有必要将代码托管一下,以防万一不慎丢失。已经相当一段时间没有使用Git了,也是趁这个来熟悉一下基本的操作。不过在使用的过程中也遇到了很多的问题,于是写下来给大家分享一下。

####一、第一次使用Git上传代码到GitHub的操作方法
  在这里网上的教程已经足够详细了,就不多加赘述了。不懂得朋友可以参考下面这一篇博客进行搭建。

  • github官方文档
    ####二、自己总结的操作步骤
      在这一部分是我总结的关于提交代码的关键步骤,以备后用!
    【1】#找到要进行托管的代码文件夹,右键运行命令(实际上是文件夹上一级):
Git Bash Here

【2】#初始化命令:

git init

【3】# 将工作文件修改提交到本地暂存区(yourProjectName是你的文件夹名称)

git add yourProjectName

【4】#提交暂存区里面的内容(your remark里面为注释)

git commit -m "your remark"

【5】#添加远程仓库地址

git remote add origin git@ github:robbin/robbin_site.git

【6】#从另一个存储库或本地分支获取并集成(整合

git pull --rebase origin master

【7】#将本地分支的更新,推送到远程主机

 git push -u origin master

####三、遇到的问题及解决办法
【1】准备上传到github 时,使用了以下命令:

$ git push origin master

出现了以下错误:

To git@github.com:xxx/xxx.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'git@github.com:xxx/xxx.git'
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.

解决方案为:

$ git pull --rebase origin master
$ git push -u origin master

【2】报出以下错误:

nothing added to commit but untracked files present

解决方案请参考:

Evan@DESKTOP-72UH89M MINGW64 /d/360极速浏览器下载 (master|REBASE 1/1)
$ git push -u origin master
To github.com:Evanlovea/weixin-app-AR-Camera-Demo.git
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to 'git@github.com:Evanlovea/weixin-app-AR-Camer                                                                                                                a-Demo.git'
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and 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.

####四、其他问题

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值