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