linux命令實戰(zhàn)本地創(chuàng)建git倉庫并遠(yuǎn)程推送到github,克隆并部署

整個操作流程可以理解為:先在本地創(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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容