GitHub


Posted by yunanpan on 2020-06-17

在多人協作的時候,需要共享同一份 repository。就像是我們會用 google 雲端共同編輯檔案的概念。那這份共享的 repository 要放在哪裡呢?當然可以選擇自己架設 git repository 的 server,而廣泛被使用的則是 GitHub。也有其他服務像是:Bitbucket、GitLab。

雖然使用 git 不一定用 GitHub,但要操作 GitHub 卻必須使用 git。之前所學的 git 相關指令,如:git addgit commit,皆是在本地端操作,而如果需要將本地端的資料推送到 GitHub,或是將 GitHub 遠端數據庫的資料拉下來,則需使用其他的指令。

如何把 code 放上 GitHub

  1. 在 GitHub 介面的右上角可以點選 new repository,在 GitHub 上建立新的數據庫。
  2. 建立好後,GitHub 會有說明告訴你下一步怎麼做
  3. git remote add origin <GitHub提供的網址>:在 GitHub 提供網址的位置架一個代號為 origin 的遠端數據庫
  4. git push -u origin master:在本地端資料推送到 GitHub 的 origin 數據庫 master 分支上:

將本地最新的改變推上 GitHub

git push origin master
git push origin <branch-name>:上傳分支

將 GitHub 最新版 pull 下來

git pull origin master

抓別人的 GitHub repository


點選 clone or download,複製網址到 git-bash。
git clone <複製的網址>:就可以將別人的 GitHub repository 複製到自己的電腦裡。
不過如果沒有權限的話,就無法 push 自己改的東西到原來的 GitHub repository 上。
如果想將自己改的東西 push 上去卻沒有權限,可以用 fork 將別人的 GitHub repo 複製到自己的帳號裡,此時會發現數據庫名稱前會是自己的帳號。再重新 clone 下來,就可成功將更動 push 到 GitHub 上了。


GitHub Pages

GitHub 有提供功能將 code 轉變成靜態網頁。可以放一些網頁的作品或是專案介紹。
在 settings 裡可選擇相關設定。


GitHub Flow

  1. git pull origin master:將遠端有更動的版本同步下來。
  2. git checkout -b <branch-name>:新增並切換到新分支
  3. 修改檔案內容
  4. git commit -am "update"
  5. git push origin <branch-name>:將有調整檔案的新分支推送到 GitHub
  6. pull request:GitHub 會自動偵測有沒有新的分支,選擇提交要推送的分支併入遠端的 master 的請求。
  7. review 後沒問題可以將分支併入 master,並刪除分支。
  8. git pull origin master:將併入後的版本同步到本地端。
  9. git branch -d <branch-name>:將本地端的新分支刪除。









Related Posts

[Preparation for Interview Basic 1] DOM Element

[Preparation for Interview Basic 1] DOM Element

AWS 遠端主機部署與連線

AWS 遠端主機部署與連線

The introduction and difference between class component and function component in React

The introduction and difference between class component and function component in React


Comments