###### tags: `ASE` `Workshop` `Azure DevOps` `Azure Repo` `Git` # Hands-on: Source Control and Azure Repo Workshop [TOC] ## 1/ Git 基本練習 - 開啟 [Azure Portal](https://portal.azure.com/) 並登入 - 選擇右上角的 Cloud Shell,選擇 Bash,點選 Create Storage  - 第一次使用Git時我們會先設定使用者名稱與信箱,於每次提交的時候顯示,讓其他成員了解提交作者是誰,git config 有分為global, project 或 folder,如果 folder 沒有就會使用 global ```.sh git config --global user.name "workshop-user-tw2023-<#>" git config --global user.email "workshop-user-tw2023-<#>@huier23outlook.onmicrosoft.com" - 設定完成後查看 ```.sh git config --list ``` - 操作結果  - Git 命令查詢 ```.sh git help ``` - 版本管理 - 建立資料夾 ```.sh mkdir GitProject cd GitProject ``` - 新增檔案並打開編輯器,`Ctrl+S` 可進行儲存 ```.sh code myFirstGitFile.txt ```  - 視窗右上角選擇 Close Editor  - 初始化專案 ```.sh git init ``` - 加入 ```.sh git add myFirstGitFile.txt git add . ``` - 提交 (Commit) ```.sh git commit -m "First commit" ``` - 建立新分支 ```.sh git branch dev ``` - 切換至分支(如果沒有先做 commit,則切換時會有問題) ```.sh git checkout dev ``` - 打開 `myFirstGitFile.txt` 修改 ```.sh code myFirstGitFile.txt ```  - 加入 ```.sh git add myFirstGitFile.txt ``` - 提交 (Commit) ```.sh git commit -m "Commit @dev" ``` - 合併至 master ```.sh git checkout master git merge dev ``` ## 2/ 上傳至版控庫 ### 設定遠端版控庫位置 - 回到 [Azure DevOps](https://dev.azure.com/where-workshop) - 選擇 `Azure Repos > Files`,將網址列複製  - 在 git 中設置 remote 位置 ``` git remote add origin <git_repo_url> ``` - 推送 ``` git push origin master ``` - 推送時會出現 Password for ...,回到 [Azure DevOps](https://dev.azure.com/where-workshop) Repo 中點選 **[Generate Git Credentials]**  - 將 PAT 複製下來並貼回 Password 欄位  - 推送完成  - 重新整理 Repo 網頁後可以看到檔案  - 選擇 **[Commits]** 可看到紀錄  <!-- ### 匯入範例程式碼 - 點選左方欄位 Repo 底下的 **[Files]**,點選頁面中的 **[Import]**  - 複製以下連結貼到 **[Clone URL]** 中 ``` https://github.com/huier23/AspNetCoreSample.git ``` - 完成後點選 **[Import]**  - 顯示正在進行匯入  - 完成後會看到成功畫面並且跳轉到匯入的程式碼  --> ### Pull Request 練習 - 點選頁面上方的 **[master]**,點選 **[+ New Branch]**  - 建立一個 `dev` 分支,點選 **[create]**  - 建立完成後會看到上方分支已經切換到 `dev`  - 修改 **[myFirstGitFile.txt]** 檔案  - 點選 **[Edit]** 可以開始修改  - 在文件中最下方填入任意文字,然後點選右上角 **[commit]**  - 會跳出 Commit 視窗,點選 **[Search work items by ID or title]**,尋找到先前建立的 task `修改 myFirstGitFile`,完成後點選下方的 **[Commit]**  - 點選左方選單 Repos 下的的 **[Pull Request]**,點選上方通知訊息條的 **[Create a pull request]**  - 確認是從 `dev` 合併到 `master`,並在 **[Reviewers]** 的欄位搜尋選擇自己,完成後點選 **[Create]**  - 接著會跳轉到 pull request 的 review 畫面,點選右上角的 **[Approve]**  - 點選旁邊的 **[Complete]**  - 確認 **[Delete dev after merging]** 是勾選狀態,並點選下方的 **[Complete merge]**  - 完成畫面  - 回到 **[Files]**,查看 **[myFirstGitFile.txt]**  - 在 `master` 上,已經更新為剛剛的修改的版本  - 找到 `修改 myFirstGitFile` 的工單查看內容,狀態也被自動異動成 Done 
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up