github代码托管

作者: Chars | 来源:发表于2016-05-07 08:47 被阅读311次

    下载github客户端软件

    1. 官网下载
    2. Google搜索,一般用于windows7以前的系统

    安装github软件

    根据软件安装指导,按步骤安装即可。

    使用git命令提交

    git config

    安装Git后首先要做的事情是设置用户名称和e-mail地址。这是非常重要的,因为每次Git提交都会使用该信息。它被永远的嵌入到了你的提交中:

        git config --global user.name "Chars Davy"
        git config --global user.email chars_d@example.com
    
    

    重申一遍,只需要做一次这个设置。如果传递了 --global 选项,因为Git将总是会使用该信息来处理你在系统中所做的一切操作。如果你希望在一个特定的项目中使用不同的名称或e-mail地址,你可以在该项目中运行该命令而不要--global选项。

    git clone

    这是一种较为简单的初始化方式,当你已经有一个远程的Git版本库,只需要在本地克隆一份:

    git  clone  git://github.com/someone/some_project.git   some_project 
    

    上面的命令就是将git://github.com/someone/some_project.git这个URL地址的远程版本库,完全克隆到本地some_project目录下。

    git init 和 git remote

    这种方式稍微复杂一些,当你本地创建了一个工作目录,你可以进入这个目录,使用git init命令进行初始化;Git以后就会对该目录下的文件进行版本控制,这时候如果你需要将它放到远程服务器上,可以在远程服务器上创建一个目录,并把可访问的URL记录下来,此时你就可以利用git remote add命令来增加一个远程服务器端,

    git  remote  add  origin  git://github.com/someone/another_project.git
    

    上面的命令就会增加URL地址为git: //github.com/someone/another_project.git,名称为origin的远程服务器,以后提交代码的时候只需要使用 origin别名即可。

    git add

    将当前更改或者新增的文件加入到Git的索引中,加入到Git的索引中就表示记入了版本历史中,这也是提交之前所需要执行的一步,

    git add app/model/user.rb
    

    就会增加app/model/user.rb文件到Git的索引中,该功能类似于SVN的add,

    git add .
    

    上面的命令会将所有改动过的文件及文件夹迭代全部添加进本地代码仓库。

    git commit

    提交当前工作空间的修改内容,类似于SVN的commit命令,

    git commit -m story #3, add user model
    

    提交的时候必须用-m来输入一条提交信息,该功能类似于SVN的commit,

    git commit –m beta
    

    上面的命令会将beta作为log显示在代码提交记录中。

    git push

    将本地commit的代码更新到远程版本库中,

    git push origin
    

    上面的命令就会将本地的代码更新到名为orgin的远程版本库中。

    git代码提交中可能遇到的问题

    问题1:

    You can't push to git://github.com/example/example_pro.git
    Use https://github.com/ example/example_pro.git
    

    解决办法:

    git remote remove origin
    git remote add origin git@github.com:user_name/user_repo.git
    git push origin
    

    原因:

    如果在git clone的时候用的是git://github.com:xx/xxx.git 的形式, 那么就会出现这个问题,因为这个protocol是不支持push的,而使用git clone git@github.com:lujinjianst/myNCCL.git就可以用git push。

    问题2:

    Permission denied(publickey).
    fatal:Could not read from remote repository.
    

    解决办法:

    在终端输入:

    ssh-keygen -t rsa -C "chars"//注意,chars为用户名
    

    如果执行成功。返回:

    Generating public/private rsa key pair. 
    Enter file in which to save the key (/home/forwhat.cn/.ssh/id_rsa): 
    

    在这里就是设置存储地址了.反正我是直接按的回车,然后还会返回:

    Enter passphrase (empty for no passphrase):
    

    再次直接回车。

    Enter same passphrase again:
    

    再次回车。

    Your identification has been saved in /home/forwhat.cn/.ssh/id_rsa. 
    Your public key has been saved in /home/forwhat.cn/.ssh/id_rsa.pub. 
    The key fingerprint is:
    
    The key's randomart image is: 
    +--[ RSA 2048]----+ 
    |                 | 
    |                 | 
    |                 | 
    |    o            | 
    |   + .  S        | 
    |  . = .  o       | 
    |   o + +o.o      | 
    |E o . o.=+.      | 
    |.+   ==+ooo.     | 
    +-----------------+ 
    

    这样SSH key就生成了。直接cat一下就好了。

    :~/a$ cat /home/forwhat.cn/.ssh/id_rsa.pub 
    

    把显示出来的直接添加到github账户设置里边的SSH keys。
    回来再git pull就开始远程拷贝代码了。

    原因:

    没有在github账号添加SSH key。

    相关文章

      网友评论

        本文标题:github代码托管

        本文链接:https://www.haomeiwen.com/subject/pzgjrttx.html