整個操作流程可以理解為:先在本地創(chuàng)建倉庫,然后在倉庫中添加文件(A、B、C)和文件夾(config.xml),然后在GitHub上建立遠(yuǎn)程庫并關(guān)聯(lián),把本地倉庫上的文件打包并推送到GitHub,然后克隆下來,并部署在/app/www中。即可以理解為開發(fā)提交代碼到遠(yuǎn)程倉庫GitHub中,然后測試clone代碼的過程。
準(zhǔn)備工作:1、以root用戶登陸自己的Linux服務(wù)器;2、git已安裝并配置好。
Git安裝配置見:http://www.itdecent.cn/writer#/notebooks/12459620/notes/13565149
一、本地創(chuàng)建git倉庫并在倉庫下新建文件及文件夾
1、新建git倉庫并初始化
[root@iZwz945po7bqabsr6de22fZ ~]mkdir -p /home/git/repositories/test.git
[root@iZwz945po7bqabsr6de22fZ ~]# cd /home/git/repositories/test.git
[root@iZwz945po7bqabsr6de22fZ test.git]#?git ?init
Initialized empty Git repository in /home/git/repositories/test.git/
2、倉庫下創(chuàng)建文件夾及xml文件
[root@iZwz945po7bqabsr6de22fZ test.git]# mkdir A
[root@iZwz945po7bqabsr6de22fZ test.git]# mkdir B
[root@iZwz945po7bqabsr6de22fZ test.git]# mkdir C
[root@iZwz945po7bqabsr6de22fZ test.git]# vi config.xml
3、編輯config.xml文件
[root@iZwz945po7bqabsr6de22fZ test.git]# vim config.xml
查看編輯后的內(nèi)容:
[root@iZwz945po7bqabsr6de22fZ test.git]# cat config.xml
hello world
~
update finish!
4、打包文件及文件夾
[root@iZwz945po7bqabsr6de22fZ test.git]# tar -zcvf ?test.tar.gz A B C config.xml
二、建立遠(yuǎn)程倉庫并關(guān)聯(lián)
1、打開Github,注冊賬號后,在右上角找到New repository,建立一個新的倉庫,如下圖:

2、點擊步驟1中的“Create repository”后,并按照github網(wǎng)上的提示輸入

3、推送test.tar.gz壓縮包到github
[root@iZwz945po7bqabsr6de22fZ test.git]# git add test.tar.gz
[root@iZwz945po7bqabsr6de22fZ test.git]# git commit -m "first commit"
[root@iZwz945po7bqabsr6de22fZ test.git]# git remote add origin git@github.com:jrainyang/istest.git
[root@iZwz945po7bqabsr6de22fZ test.git]# git push -u origin master
在推送時報錯了,如下:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
這個應(yīng)該是很多github新手經(jīng)常出錯的問題,這個就是沒有在你的github上添加一個公鑰。
解決方法如下:
1)可以用 ssh -T git@github.com去測試一下

圖上可以明顯看出缺少了公鑰
2)生產(chǎn)公匙,如下圖

3)cat 一下? 把出現(xiàn)的key 復(fù)制下來
[root@iZwz945po7bqabsr6de22fZ ~]# cat /root/.ssh/id_rsa.pub

4)在github上添加剛剛生成的公鑰




4、再次推送test.tar.gz壓縮包到github
[root@iZwz945po7bqabsr6de22fZ test.git]# git add test.tar.gz
[root@iZwz945po7bqabsr6de22fZ test.git]# git commit -m "first commit"
[root@iZwz945po7bqabsr6de22fZ test.git]# git remote add origin git@github.com:jrainyang/istest.git
[root@iZwz945po7bqabsr6de22fZ test.git]# git push -u origin master

5、在GitHub頁面可看到本地庫一樣的內(nèi)容

6、克隆遠(yuǎn)程庫到app/www,并部署
[root@iZwz945po7bqabsr6de22fZ app]# mkdir www
[root@iZwz945po7bqabsr6de22fZ www]# git clone git@github.com:jrainyang/istest.git
[root@iZwz945po7bqabsr6de22fZ www]# tar -zxvf test.tar.gz
