美文网首页
Git 连接github

Git 连接github

作者: Qiuty | 来源:发表于2019-07-25 20:02 被阅读0次

大概如下:

Git连接github

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

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


image.png
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:

解决该问题的播客

错误四


image.png

是因为远程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]

image.png

git教程

相关参考播客

相关文章

  • github与git之间怎么建立连接

    github与git之间怎么建立连接 Git与 Github的连接与使用 本地项目上传到github 报错“mas...

  • git的使用

    Git连接github的详细使用 安装git [git下载地址]: https://git-for-windows...

  • git连接 github

    1.Git初始化设置 首先设置用户名跟邮箱 global(全局变量) git config --global us...

  • Git连接Github

    1. 在本地安装Git 新建git本地仓库,在仓库里点击右键打开git命令行界面我在本地文件建立了这个文件夹作为一...

  • Git 连接github

    大概如下: 详细如下:如果使用本文命令,请仔细选择,因为添加一些相关命令以供参考。 1 本地仓库 1.1...

  • 【Git】连接github

    git pull/push这种命令时可能会要你输入username/password,如果在github设置ssh...

  • github ssh key 添加成功但是无法clone项目

    $ ssh -T git@github.com测试连接成功,但是clone时出现 git@github.com[m...

  • git使用过程出现的问题

    1、本地连接github 执行git remote addoriginhttps://github.com/han...

  • git 和 github

    2017-07-15 git 连接 github 远程上传文件

  • Python相关文章(5)

    环境部署 通过pycharm使用git[图文详解] pycharm使用github Pycharm连接Github...

网友评论

      本文标题:Git 连接github

      本文链接:https://www.haomeiwen.com/subject/pyjkrctx.html