安装github

来源:互联网 发布:网络合同无效管辖法院 编辑:程序博客网 时间:2024/04/30 03:05
  1. 安装github

    1.1 在linux上安装github

    首先可以试着在shell中输入git,若提示没有该命令,则可以使用sudo apt-get install git 来安装,

    1.2 在windows上安装github

    可以在http://msysgit.github.io下载,然后默认安装就可以了,安装完成后有图形用户界面,就是下面图中的GitHub,章鱼猫的那个图标。

  2. 配置本地和远程git仓库

    2.1 配置本地环境

    打开 git shell ,windows用户看起来应该是下面这个样子 
    git shell 
    linux用户直接在shell中输入git即可 
    接着,在shell中配置自己的信息(请忽略‘$’符号)

    $ git config --global user.name "Your Name"$ git config --global user.email "email@example.com"

    2.2 配置远程仓库

    我选用的github作为远程仓库使用的,注册过程不在详细叙述。 
    申请好账号之后,点击右上角自己的头像在弹出菜单中选择settings,看起来像下面这样: 
    githubHomePage

    在新界面中的左侧列表中选择SSH keys,点击右上角的 Add SSH key,看起来像下面这样

    githubSSHkey

    然后我们回到shell中,继续生成密钥等工作 
    github官网有详细教程,链接地址请点这里,github网站访问速度慢的可以继续看下去,去github官网看的请跳过本章

    2.3 生成ssh keys

    首先检测有没有已经生成好的ssh key,windows用户可以查看C:\Users\username\.ssh文件夹下有没有github_rsa文件,linux用户可以在shell中输入ls -al ~/.ssh,若有,请跳过本步骤。 
    在git shell 中输入下面第一条命令,linux用户注意不用加 sudo

    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 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

    2.4 将生成的key 添加到 ssh-agent

    # start the ssh-agent in the backgroundeval "$(ssh-agent -s)"#windows用户上面这条语句报错的话就改成 `ssh-agent -s`# Agent pid 59566ssh-add ~/.ssh/id_rsa

    2.5 将ssh key添加到你的github账户中

    回到我们打开的添加SSHKEY网页,点击Add SSH Key,在Title中添加说明,用记事本之类的编辑器打开生成的id_rsa.pub(位于.shh文件中),复制其中的内容到Key中,然后点击Add Key

    2.6 测试连接

    打开 git shell 输入ssh -T git@github.com,若提示

    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.

    说明连接成功,若有问题,请点击这里

0 0
原创粉丝点击