最近要用 C# 開發一個新的項目,所以需要在 Windows 局域網環境下構建一個 git server。
在 Windows 7 上搭建 git server 的方案很多。比如:
1. gogs
2. bamboo(https://www.atlassian.com/software/bamboo/)
3. Github for Windows + CoqSSH(https://github.com/msysgit/msysgit/wiki/Setting-up-a-Git-server-on-Windows-using-Git-for-Windows-and-CopSSH)
這里選 gogs 實現。
平台:Win7 x64
工具:nssm、gogs_v0.8.43_windows_amd64.zip、MySQL、git 工具
0. 安裝 MySQL;
1. 在 MySQL 中創建 gogs 數據庫:
create database gogs;
2. 安裝 Git 工具。這一步是為了 gogs 服務端能夠找到 git 命令。由於此前我在機器上已經安裝了 Github for Windows 工具,所以 git 也附帶的安裝了。如果你的機器上沒安裝 git。可以去下載一個並安裝。
3. 解壓 gogs_v0.8.43_windows_amd64.zip 到目的位置;
4. 注冊 gogs 服務:
(1) 修改 gogs/scripts/windows/install-as-service.bat,將其中的:
SET gogspath=C:/gogs
路徑信息修改為本機 gogs 安裝路徑;
(2) 安裝 nssm,並確保 nssm 的安裝路徑已添加到 %PATH% 環境變量中;
(3) 以管理員權限運行 install-as-service.bat;
5. 打開瀏覽器,輸入:127.0.1.1:3000,進入配置界面(我只修改了代碼倉庫存放路徑這一項)。完成配置后,gogs/custom/conf 目錄下會生成一個新的 app.ini 配置文件。
6. 注冊用戶,登錄用戶。默認情況下,注冊的第一個用戶將具有管理員權限。
7. 在局域網情況下,Garvatar 不可用。所以用戶最好設置一個自定義頭像。
8. 在工作機器上安裝一個 git 客戶端工具。可選的帶 GUI 的客戶端工具有:
SourceTree
TortoiseGit
參考資料:
1. https://gogs.io/docs/installation/install_from_binary.html
2. https://gogs.io/docs/installation/configuration_and_run
3. https://gogs.io/docs/installation/run_as_windows_service
4. https://gogs.io/docs/advanced/configuration_cheat_sheet.html