fly
git 搭建測試頁面
步驟一:
- 登陸GitHub主頁
- 點擊右上角
+
號,選擇New Repository - 再打開的Create a new repository頁面,按照如下設(shè)置:
- Owner:這個是賬戶,如果你想給其他賬戶創(chuàng)建Repository就選擇其他的
- Repository name|:這里是填寫創(chuàng)建資源庫名稱
- Repository權(quán)限設(shè)置:
- [x] Plublic
- [ ] Private
Public免費的,不過任何人都能訪問
Private收費的,限制其他人訪問
這個根據(jù)需求選擇吧,一般相信Public夠用了,反正是玩而已
- Initialize this repository with a README
>使用README初始化這個倉庫
>這將讓您立即將存儲庫克隆到計算機。如果要導(dǎo)入現(xiàn)有存儲庫,請?zhí)^此步驟
>這里勾選,因為我是創(chuàng)建新的
- 然后點擊創(chuàng)建Create repository,即可創(chuàng)建一個倉庫
步驟二:
-
添加ssh免密鑰登陸(本地操作)
# ssh-keygen -t rsa -C "你的郵箱賬戶(好像也可以不寫)"
-
拷貝生成的id_rsa.pub內(nèi)容
# cat id_rsa.pub
點擊右上角頭像,選擇Setting,打開頁面選擇SSH and GPG keys
在SSH and GPG keys右側(cè)點擊SSH keys右邊的New SSH key,在彈出的框中粘貼剛才復(fù)制的密鑰,然后單擊添加即可
-
本地驗證是否成功
# ssh -T git@github.com Hi admin! You've successfully authenticated, but GitHub does not provide shell access.
如有以上提示就說明成功了,這個是測試,后面拉去、上傳代碼文件不需要這樣操作
步驟三:
-
本地創(chuàng)建與github同名的文件夾
# mkdir project
project為你github上的倉庫名
-
首次初始化本地倉庫
# git init
-
設(shè)置github登錄名和郵箱
# git config --global user.name "your name" # git config --global user.email "your email"
-
將該Github版本倉庫添加到本機的遠程列表中
# git remote add origin git@github.com:yuoraccount/your Repostiry.git
-
添加內(nèi)容至test.md
# echo "test is ok" >test.md
-
提交文件到本地緩存庫
# git add test.md
-
提交到本地git版本庫
# git commit -M "add words"
-
同步本地版本庫至github
# git push origin master
備注:首次同步到github需要添加-u
參數(shù),或者先pull下
容易遇到的問題
error:failed to push some refs to ...
Dealing with “non-fast-forward” errors
From time to time you may encounter this error while pushing:
$ git push origin master
To ../remote/
! [rejected] master -> master (non-fast forward)
error: failed to push some refs to '../remote/'
To prevent you from losing history, non-fast-forward updates were rejected
Merge the remote changes before pushing again. See the 'non-fast forward'
section of 'git push --help' for details.
這個問題github上面的代碼里面已經(jīng)有你本地新添加的代碼文件內(nèi)容,他不允許直接覆蓋
解決方法:
# git pull origin master
重新拉去一次,然后重新提交
如何刪除github上不想要或者上傳錯的文件:
# git rm --cached filename
# git commit -m "hehe"
# git push origin
刷新頁面即可消失
- 刪除后有時反應(yīng)特別慢,得登上3分鐘左右的才能生效,只要保證本地操作成功,那就等下,多刷新幾下頁面再看看