大概如下:



详细如下:如果使用本文命令,请仔细选择,因为添加一些相关命令以供参考。

1 本地仓库

1.1 创建git 仓库
git init  # 初始化本地仓库

git --version  # 查看Git版本
1.2 配置git 仓库
方法一:
git config --global user.name "你的注册用户名"
git config --global user.email "你的注册邮箱" 方法二:
直接编辑 vim .git/config "不推荐新手使用"
[branch "master"]
remote = origin
merge = refs/heads/master
1.3 本地使用git 仓库
git clone "分支ssh路径";
git add [*]/git / rm [*]; #提交增加文件和修改文件到缓存区
git commit -m "代码提交信息";#将改动提交到head
git sheckout /#切换分支 #删除本地仓库
ls -la #查看.git 文件
rm -rf .git

2.远程仓库

2.1创建远程仓库

若新建远程仓库的时候,点击自动创建了README文件会报错 (解决方法在最后)

2.2 配置秘钥

2.2.1 检查秘钥

cd ~/.ssh   # 检查秘钥

2.2.2 生成秘钥

ssh-keygen -t rsa -C "macbookpro"  #-C 是自己设置的信息

要求输入密码, 不用输入,直接回车(务必仔细)

2.2.3 公钥配置到git hub上

3 连接本地仓库和远程仓库

远程仓库的地址一般是{url}.git

git remote add origin {github 仓库}

4. 配置完成后

提交代码:git push [-u] origin master; //-u 第一次使用时候,没有远程仓库是加u推送

获取代码:git pull

5 . 相关错误

错误一:两地仓库代码不同时

fatal: refusing to merge unrelated histories

git pull --allow-unrelated-histories

错误二:配置信息与github 上信息不同:

You asked to pull from the remote 'origin', but did not specify

a branch. Because this is not the default configured remote

for your current branch, you must specify a branch on the command line



vim .git/config   

然后添加
[branch "master"]
remote = origin
merge = refs/heads/master

错误三:

error: Your local changes to the following files would be overwritten by merge:

解决该问题的播客

错误四



是因为远程repository和我本地的repository冲突导致的

1.使用强制push的方法:

$ git push -u origin master -f

这样会使远程修改丢失,一般是不可取的,尤其是多人协作开发的时候。

2.push前先将远程repository修改pull下来

$ git pull origin master

$ git push -u origin master

3.若不想merge远程和本地修改,可以先创建新的分支:

$ git branch [name]

然后push

$ git push -u origin [name]

chuan1.创建分支

git branch new
git checkout new 移动到new 分支
git checkout -b new master 从master上创建分支并检出到该分支
git merge new 在其他分支上合并new分支
git checkout

SSH 使用

1.很多服务器都是需要认证的,ssh认证是其中的一种。在客户端生成公钥,把生成的公钥添加到服务器,你以后连接服务器就不用每次都输入用户名和密码了。
2.很多git服务器都是用ssh认证方式,你需要把你生成的公钥发送给代码仓库管理员,让他给你添加到服务器上,你就可以通过ssh自由地拉取和提交代码了。

git教程

相关参考播客

最新文章

  1. sublime3 插件
  2. Date 对象中的 getYear 和 getFullYear方法
  3. [2015hdu多校联赛补题]hdu5301 Buildings
  4. IoC和DI的理解
  5. LINK : fatal error LNK1117: syntax error in option 'VERSION:1.6.5'
  6. POJ3038 Flying Right
  7. swift:入门知识之简单值
  8. c语言write与python的struct模块交互
  9. linux 系统磁盘分区之fdisk
  10. Swift optional详解
  11. Linux下动态链接库和静态链接库
  12. 为自己的Android应用添加广告
  13. C# 伪造 referer 提交数据
  14. centos简单的后台运行
  15. pyqt5 -——基本功能(HelloWorld)
  16. 爬虫之 案列1补充(pipelines优化)
  17. Android hdpi ldpi mdpi xhdpi xxhdpi适配详解
  18. inventory file 与hosts patterns (ansible 机器清单 与 主机匹配模式)
  19. 深入浅出的webpack4构建工具---比mock模拟数据更简单的方式(二十一)
  20. css3 transition属性实现3d动画效果

热门文章

  1. 前端开发之BOM和DOM(转载)
  2. jq实现简单手风琴效果
  3. php Restful设计
  4. Appium + python 自动化测试环境配置
  5. HDU 3397"Sequence operation"(线段树区间和并)
  6. 《Spring 5官方文档》 Spring AOP的经典用法
  7. redis_Cacha 爬虫链接redis配置文件
  8. PhpStorm terminal无法输入命令的解决方法
  9. 2019-9-2-C#命令行解析工具
  10. win10 uwp 解决 SerialDevice.FromIdAsync 返回空