iT邦幫忙

2024 iThome 鐵人賽

DAY 3
0

如何開始使用 GitHub Codespace

使用者可以以 GitHub.com、Visual Studio Code 或 GitHub CLI 方式建立 Codespace。目前有四種方法讓您在 GitHub.com 上建立新的 Codespace:

  • 從 GitHub 範本或任何 GitHub.com 上的範本 Repository 來開始新專案

https://ithelp.ithome.com.tw/upload/images/20240916/2009149401npEdGezf.png

 

  • 從 Repository 中的分支進行新功能工作
    你可以直接點選 + 按鈕在目前分支直接建立 codesapce;如果有想要選擇特定分支與機器規格,請點選 … 按鈕 > 點選 new with option 來選擇分支、虛擬機器區域與類型以符合開發人員需求。

https://ithelp.ithome.com.tw/upload/images/20240916/20091494nYPmisOHJ3.png

https://ithelp.ithome.com.tw/upload/images/20240916/20091494S22ktyrGfI.png

 

  • 從開啟的 Pull Request 探索進行中工作。

https://ithelp.ithome.com.tw/upload/images/20240916/20091494be8UqKas1h.png

 

  • 從 Repository 歷程記錄中的 commit,在特定時間點調查 Bug

https://ithelp.ithome.com.tw/upload/images/20240916/20091494lRt8UXDEB7.png

 
 
 

GitHub Codspace 介面介紹

開啟 GitHub Codespace,你應該會發現為 Visual Studio Code 介面但在網頁上呈現。左邊主要為檔案總管、搜尋、Git 版本管理、啟動偵錯、擴充套件與 GitHub Pull Request;中間區域為主要作業區;下方為終端機可以輸入指令。
https://ithelp.ithome.com.tw/upload/images/20240916/20091494cdB8BPweQW.png

 

使用過程中會啟用自動儲存功能,這意味一個短暫時間內會自動儲存;如果此時關閉瀏覽器,重新開啟後會回到關閉前狀態。一般來說,正式的儲存方式是 commit 並 push 至儲存庫,如果有尚未 commit 時候停用 Codesapce,會有訊息提示有 uncommitted change。在刪除 Codespace 時仍未 commit 並 push 至儲存庫,則這些變更會遺失。
https://ithelp.ithome.com.tw/upload/images/20240916/20091494B6eH6Yzei9.png

 

此外,為了避免使用者忘記停止 Codesapce 而產生費用,預設設定逾時停止予刪除時間。使用者如果閒置 10 分鐘沒有使用,則會自動停止 Codespace,此設定最大值為 240 分鐘;使用者如果閒置時間超過 30 天,則會自動刪除 Codespace,此設定值最大為 30 天。

你能在 Setting > Codespace 找到相關設定

https://ithelp.ithome.com.tw/upload/images/20240917/20091494RkCrAoY28x.png

 
 
 

Codespace 生命週期

從前面的介紹,讀者應該會發現 Codespace 至少包含育種基本操作: 建立、停止、啟動與刪除,這即為 Codespace 生命週期。您只須謹記隨時 commit 與 push 更改內容至 repos,以避免刪除行為造成變更遺失。

https://ithelp.ithome.com.tw/upload/images/20240917/20091494FZ54zXLsyj.png

 

你可以在 https://github.com/codespaces 確認目前所有啟動中的 Codespaces 狀態並進行相關操作 (如更改名稱、開啟 codespace、變更機器類型與刪除);也能點選右上角 New Codespace 按鈕,選擇 Repository、Branch、Region 與機器類型,建立新的 Codespace。
https://ithelp.ithome.com.tw/upload/images/20240917/20091494PFazFrCvLp.png

https://ithelp.ithome.com.tw/upload/images/20240917/20091494siV4BDUwKO.png

 
 
 

後記

雖然 Codespace 線上版本介面與 Visual Studio Code 幾乎完全相同,但實際在使用上仍有一點差異,考量到計費與其生命週期,養成好的習慣隨時進版控以確保辛苦不會付諸流水。下一篇文章會說明如何使用擴充套件與進行個人化設定。


上一篇
隨開即用的開發環境 GitHub Codespace
下一篇
GitHub Codespace 延伸模組與個人化設定
系列文
現代化應用程式開發與維運 - GitHub Codespace 與 GitHub Copilot13
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言