目前碰到的工作環境,幾乎都有裝 Visual Studio,首次連上 TFS Git 時會使用 Visual Studio UI 設定使用姓名、Email,記憶連線 TFS 伺服器的帳號密碼,之前改用 Git 命令列工具什麼都不用設定就能操作。這次協助設定了一個沒有 Visual Studio 純用 Git 命令列工具連 TFS 主機的工作環境,得到一些新經驗。

我選擇安裝 Cmder with Git for Windows,Git 工具與命令列環境一次搞定。開啟 Cmder,建立 TFS Collection 對應的資料夾,使用以下指令設定使用者名稱跟 Email,並設定採用 Windows 內建的認證管理機制:

git config --global user.name "姓名"
git config --global user.email "user@mail.com.tw"
git config --global credential.helper wincred

基本上設好這些就可以上工,接著下 git clone httq://tfs-server:8080/tfs/COLLECTION-NAME/_git/PROJECT-NAME 抓原始碼,因為沒連過這台伺服器,理論上應跳出帳號密碼對話框如下圖:

但不知何故,在這台主機上沒跳問帳號密碼,直接回傳 fatal: Authentication failed for 'https://....' 錯誤。

爬文得知,Git 對各主機的登入資訊在 Windows 作業系統是保存在 Crendential Manager/Windows Credentials / Generic Credentials:如下圖:

若系統沒彈出帳密視窗,手動新增一筆就是了。URL 的格式如 git:http://tfs-server:8080,輸入帳號密碼儲存(記得類別為 Generic Credentials),設定好重新下 git clone 就能使用指定的身分認證登入 TFS 取回程式碼囉。

Tips of setting Windows credential for TFS Git.


Comments

Be the first to post a comment

Post a comment