Git — 关联远程仓库

远程仓库

1. 生成公私钥

$ ssh-keygen -t rsa -C "aaa@163.com"把邮件地址换成自己的邮件,然后一路回车,使用默认值即可;

Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):  –>加粗的为路径
Created directory ‘/c/Users/Administrator/.ssh’.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa.  –>私钥
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub.  –>公钥
The key fingerprint is:
SHA256: …略… aaa@163.com
The key’s randomart image is: 略

2. 如何将SSH添加到Github上?

这里写图片描述

3. 如何关联本地仓库和远程仓库?

$ git remote add origin git@github.com:github的账户名/github的仓库名.git
远程库的名字就是origin,这是Git默认的叫法,也可以改成别的;

4. 如何将本地仓库的文件推送到远程仓库中?
  1. 如果远程库是空的,那么在第一次推送master分支时,加上-u参数,Git不但会把本地的master分支内容推送的远程新的master分支,还会把本地的master分支和远程的master分支关联起来,在以后的推送或者拉取时就可以简化命令。
    $ git push -u origin master

  2. 如果远程库不为空
    $ git push origin master

5. 如何将远程仓库中的文件clone到本地

Git支持多种协议,默认的git://使用ssh,但也可以使用https等其他协议。

  • SSH协议:$ git clone git@github.com:github的账户名/github的仓库名.git
  • Https协议:$ git clone https://github.com/github的账户名/github的仓库名.git
6. git pull仓库出现refusing to merge unrelated histories

git pull origin master --allow-unrelated-histories


参考

git无法pull仓库refusing to merge unrelated histories

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值