mac下github代码仓库建立流程

  1. github.com上注册账户,建立代码仓库(免费用户只能建立公共仓库)

  2. 安装git客户端(Tower)
  3. 测试连接。github使用ssh连接,需要设置ssh,利用ssh-keygen生成密钥对:

    在终端 打开.ssh目录,cd ~/.ssh

    ssh-keygen
    回车Generating public/private rsa key pair.
    Enter file in which to save the key (/Users/admin/.ssh/id_rsa): demo_rsa
    Enter passphrase (empty for no passphrase): 
    Enter same passphrase again: 
    Your identification has been saved in demo_rsa.
    Your public key has been saved in demo_rsa.pub.
    The key fingerprint is:
    30:de:c3:ac:35:41:26:f0:86:42:8e:fa:3c:f6:04:59 admin@admindeMac-mini.local
    The key's randomart image is:
    +--[ RSA 2048]----+
    |  . ... o        |
    | +   o +         |
    |. o E = .        |
    |.  + o * .       |
    |. o   . S        |
    | o .   o o       |
    |  = . .          |
    | . +             |
    |    .            |
    +-----------------+

    生成demo_rsa(私钥)demo_rsa.pub(公钥)两个文件。

    打开github中的代码仓库项目,进入项目settings->Deploy Keys->add deploy key,拷贝demo.rsa.pub中的全部内容到Key中,Add key保存。

    使用demo_rsa测试连接,在终端输入: ssh -v git@github.com -i demo_rsa 回车

    debug1: Reading configuration data /etc/ssh_config
    debug1: /etc/ssh_config line 20: Applying options for *
    debug1: Connecting to github.com [192.30.252.128] port 22.
    debug1: Connection established.
    debug1: identity file wsw_rsa type 1
    debug1: identity file wsw_rsa-cert type -1
    debug1: Enabling compatibility mode for protocol 2.0
    debug1: Local version string SSH-2.0-OpenSSH_6.2
    debug1: Remote protocol version 2.0, remote software version libssh-0.6.3
    debug1: no match: libssh-0.6.3
    debug1: SSH2_MSG_KEXINIT sent
    debug1: SSH2_MSG_KEXINIT received
    debug1: kex: server->client aes128-ctr hmac-sha1 none
    debug1: kex: client->server aes128-ctr hmac-sha1 none
    debug1: sending SSH2_MSG_KEXDH_INIT
    debug1: expecting SSH2_MSG_KEXDH_REPLY
    debug1: Server host key: RSA 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
    debug1: Host 'github.com' is known and matches the RSA host key.
    debug1: Found key in /Users/admin/.ssh/known_hosts:1
    debug1: ssh_rsa_verify: signature correct
    debug1: SSH2_MSG_NEWKEYS sent
    debug1: expecting SSH2_MSG_NEWKEYS
    debug1: SSH2_MSG_NEWKEYS received
    debug1: Roaming not allowed by server
    debug1: SSH2_MSG_SERVICE_REQUEST sent
    debug1: SSH2_MSG_SERVICE_ACCEPT received
    debug1: Authentications that can continue: publickey
    debug1: Next authentication method: publickey
    debug1: Offering RSA public key: wsw_rsa
    debug1: Server accepts key: pkalg ssh-rsa blen 279
    debug1: read PEM private key done: type RSA
    debug1: Authentication succeeded (publickey).
    Authenticated to github.com ([192.30.252.128]:22).
    debug1: channel 0: new [client-session]
    debug1: Entering interactive session.
    debug1: Sending environment.
    debug1: Sending env LANG = zh_CN.UTF-8
    PTY allocation request failed on channel 0
    debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
    Hi redparrots/cpp2txt! You've successfully authenticated, but GitHub does not provide shell access.
    debug1: channel 0: free: client-session, nchannels 1
    Connection to github.com closed.
    Transferred: sent 3448, received 1968 bytes, in 0.9 seconds
    Bytes per second: sent 3796.5, received 2166.9
    debug1: Exit status 1

    出现绿色部分,说明授权成功

    如出现
    ....
    debug1: Offering RSA public key: /Users/admin/.ssh/id_rsa
    debug1: Authentications that can continue: publickey
    debug1: Trying private key: /Users/admin/.ssh/id_dsa
    debug1: No more authentication methods to try.
    Permission denied (publickey).

    说明使用的密钥不匹配。(注意:ssh如果没有指定 -i [rsa path]参数,默认使用id_rsa授权文件, 你可以/etc/ssh/ssh_config文件中改变IdentitiyFile 所指向的默认授权文件;-v 参数打开调试信息

  4. git 克隆github项目到本地

    git clone https://github.com/redparrots/cpp2txt.git

    git clone命令详细命令可参照git clone参数详解

  5. git 添加本地文件

    git add -A

  6. git 提交更改

    git commit -m "commit info"

  7. git 推送本地更改到github

    git push

  8. git 更新到本地

    git pull

  9. 更多git命令可参考http://www.oschina.net/question/565065_86025
posted @ 2014-04-01 18:27  sisiblog  阅读(535)  评论(0)    收藏  举报