git添加远程仓库

来源:互联网 发布:标点符号检查软件 编辑:程序博客网 时间:2024/04/30 13:00

首先确保你已经安装了git ,否则下面的就不要看了,先去安装git吧。

一、检查SSH key

ssh key是一种确定能相信的计算机的方法,而且不涉及密码。

      首先要检查一下你的电脑上是否已经存在ssh key,打开git bash输入:

ls -al ~/.ssh

检查这个目录看是否已经有一个公开的ssh key,它的默认的文件名如下:id_dsa.pub、id_rsa.pub

如果你已经有了一个公有的和私有的密钥,那你可以直接跳过第二步和第三步。

二、创建ssh key

首先,你要在github上注册一个账号。然后在git bash里输入:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"# Creates a new ssh key, using the provided email as a label# Generating public/private rsa key pair.
然后,你可能遇到下面的提示,笔者建议保持默认,直接enter。

Enter file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]
接着,你被要求输入一个密码:
Enter passphrase (empty for no passphrase): [Type a passphrase]# Enter same passphrase again: [Type passphrase again]

输入密码后,你将得到如下提示:
Your identification has been saved in /Users/you/.ssh/id_rsa.# Your public key has been saved in /Users/you/.ssh/id_rsa.pub.# The key fingerprint is:# 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@example.com
看到这,你的ssh key就创建完成了。
三、添加ssh key到ssh代理里
要配置的ssh-agent程序使用您的SSH密钥。在git bash里输入:
# start the ssh-agent in the backgroundssh-agent -s# Agent pid 59566
添加ssh key 到ssh-agent.
ssh-add ~/.ssh/id_rsa

四、添加ssh key到你的账户
登陆你的github,点击settings,然后点击ssh keys,点击add ssh key,把你的后缀为.pub的公开密钥粘贴到里面,
然后点击add  key
五、测试连接
打开git bash输入:
ssh -T git@github.com# Attempts to ssh to GitHub
你会看到如下信息:
The authenticity of host 'github.com (207.97.227.239)' can't be established.# RSA key fingerprint is 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.# Are you sure you want to continue connecting (yes/no)?

输入yes后会看到:

Hi username! You've successfully authenticated, but GitHub does not# provide shell access.
如果用户名是你的,则恭喜你,连接成功。

六、添加远程库

1、在github上创建一个版本库,test。

        2、在本地创建一个版本库,test。

3、打开git bash输入:

$ git remote add origin git@github.com:账户名/test.git
用户名改成你的github用户名。这样就可以把本地库与远程库关联起来。

 git push -u origin master  
    输入上面的代码可以把本地的内容上传到github上。
git clone git@github.com:用户名/test.git
输入上面一行代码可以把远程库的内容克隆到本地。











      


0 0
原创粉丝点击