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

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

2018-02-07 00:00 183 查看

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

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

一、第一次使用Git上传代码到GitHub的操作方法

  在这里网上的教程已经足够详细了,就不多加赘述了。不懂得朋友可以参考下面这一篇博客进行搭建。

- 如何用git将项目代码上传到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】准备上传到git
4000
hub 时,使用了以下命令:

$ 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


解决方案请参考:

- nothing added to commit but untracked files present解决方法

【3】
此类错误尚未解决,在提交到远程仓库时发生,可能与文件无访问权限有关,但尚不明确,望大神赐教!


发生以下错误:

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.


四、其他问题

fatal: Could not read from remote repository.的解决办法
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: