github使用教程

教程默認已裝好github客戶端,環境變量已配置好。


1.註冊賬戶以及創建倉庫

要想使用github第一步當然是註冊github賬號了。之後就可以創建倉庫了(免費用戶只能建公共倉庫),Create a New Repository,填好名稱後Create,之後會出現一些倉庫的配置信息,這也是一個git的簡單教程。

2.配置Git

首先在本地創建ssh key;


$ ssh-keygen -t rsa -C "[email protected]"

後面的[email protected]改爲你的郵箱,之後會要求確認路徑和輸入密碼,我們這使用默認的一路回車就行。成功的話會在~/下生成.ssh文件夾,進去,打開id_rsa.pub,複製裏面的key。

回到github,進入Account Settings,左邊選擇SSH Keys,Add SSH Key,title隨便填,粘貼key。爲了驗證是否成功,在git bash下輸入:

$ ssh -T [email protected]

如果是第一次的會提示是否continue,輸入yes,會提示Enter passphrase for key,輸入你的github密碼,輸入正確後,就會看到:You've successfully authenticated, but GitHub does not provide shell access 。這就表示已成功連上github。

接下來我們要做的就是把本地倉庫傳到github上去,在此之前還需要設置username和email,因爲github每次commit都會記錄他們。

$ git config --global user.name "your name"$ git config --global user.email "[email protected]"

進入要上傳的倉庫,右鍵git bash,添加遠程地址:

$ git remote add origin [email protected]:yourName/yourRepo.git

後面的yourName和yourRepo表示你再github的用戶名和剛纔新建的倉庫,加完之後進入.git,打開config,這裏會多出一個remote “origin”內容,這就是剛纔添加的遠程地址,也可以直接修改config來配置遠程地址。如果出現錯誤:fatal: Not a git repository (or any of the parent directories): .git,則先執行一下git init即可。把生成在本地桌面的隱藏文件夾.git放到你的項目根目錄下。

3.提交、上傳

接下來在本地倉庫裏添加一些文件,比如README,


$ git add README$ git commit -m "first commit"

上傳到github:

$ git push origin master

git push命令會將本地倉庫推送到遠程服務器。
git pull命令則相反。

修改完代碼後,使用git status可以查看文件的差別,使用git add 添加要commit的文件,也可以用git add -i來智能添加文件。之後git commit提交本次修改,git push上傳到github。如果出錯:error: failed to push some refs to '[email protected]:torfuzx/beeblog.git'hint: ,則先 git pull。



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