Github 環境搭建

1、下載git   地址: https://git-scm.com/

2、安裝

3、查看是否安裝成功,命令:

git version

返回結果:git version 2.15.1 (Apple Git-101)

4、本地電腦關聯到github

  1)註冊github: https://github.com/ (有賬號的自動忽略)

  2)Git SSH Key 生成,步驟 :

      1> 設置Git的user name和email:

        $ git config --global user.name "test"
        $ git config --global user.email "[email protected]"
            2> 生成SSH密鑰過程: 
3> 查看是否已經有了ssh密鑰 , 如果沒有密鑰則不會有此文件夾,有則備份刪除
            4>生成密鑰:

$ ssh-keygen -t rsa -C “haiyan.xu.vip@gmail.com”
    按3個回車,密碼爲空。

                Your identification has been saved in /home/tekkub/.ssh/id_rsa.
                Your public key has been saved in /home/tekkub/.ssh/id_rsa.pub.
                The key fingerprint is:
                ………………

                最後得到了兩個文件:id_rsa和id_rsa.pub

            5> 添加密鑰到ssh:ssh-add 文件名
                需要之前輸入密碼。
            6> 在github上添加ssh密鑰,這要添加的是“id_rsa.pub”裏面的公鑰。

            打開https://github.com/ ,登陸xuhaiyan825,然後添加ssh。


            7>測試:ssh [email protected]

            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
            Warning: Permanently added ‘github.com,207.97.227.239′ (RSA) to the list of known hosts.
            ERROR: Hi tekkub! You’ve successfully authenticated, but GitHub does not provide shell access
            Connection to github.com closed.


5、 開始使用github

        一、clone項目到本地:
            1.獲取源碼:

       $ git clone   https://github.com/zhangsan/test.gi
      2.這樣你的機器上就有一個repo了。

            3.git於svn所不同的是git是分佈式的,沒有服務器概念。所有的人的機器上都有一個repo,每次提交都是給自己機器的repo
            倉庫初始化:git init

            生成快照並存入項目索引:git add文件,還有git rm,git mv等等…

            項目索引提交:git commit

            4.協作編程:
            將本地repo於遠程的origin的repo合併,推送本地更新到遠程:

        git push origin master

            更新遠程更新到本地:

        git pull origin master

            補充:
                添加遠端repo:

        $ git remote add upstream     https://github.com/zhangsan/test.git
            重命名遠端repo:
        $ https://github.com/zhangsan/test.git  爲“stream”

    二、本地電腦提交到github

        1.github創建一個項目

        2.找到本地項目文件目錄

        3.在命令行中,輸入“git init”,使Test文件夾加入git管理;
       4.輸入“git add -A”(-A代表保存本次改變的所有內容),將Test文件夾全部內容添加到git。
     5.輸入“git commit -m "first commit"”(“git commit -m "提交信息"”)
       6.輸入“git remote add origin https://github.com/zhangsan/test.git
”(git remote add origin 你自己的https地址),連接你的guthub倉庫。
        7.輸入“git push -u origin master”,上傳項目到Github。這裏會要求輸入Github的賬號密碼,按要求輸入就可以。




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章