Windows 环境搭建 git 服务
有时候在本地开发个人项目, 需要对代码进行版本管理, 可在 Windows 上搭建一个自己使用的 git 服务器
当前搭建系统环境
Windows10
安装Git
去官网(https://git-scm.com/) 下载 windows 版 git 并安装
安装OpenSSH
去 github 上(https://github.com/PowerShell/Win32-OpenSSH/releases) 下载并安装 OpenSSH
1. 将下载好的 OpenSSH-Win64 解压并移动到 C:\Program Files 目录下
2. 使用管理员权限打开 cmd 命令, 依次执行以下命令
# 移动到OpenSSH安装目录
cd C:\Program Files\OpenSSH-Win64
# 安装
powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1
# 设置服务
sc config sshd start=auto
# 启动服务
net start sshd
3. 将 OpenSSH 设置到环境变量中
4. 修改注册表,修改 OpenSSH 默认 shenll
打开 cmd 运行 regedit, 打开注册表。 依次选择 HKEY_LOCAL_MACHINE -> SOFTWARE -> OpenSSH。 添加变量 DefaultShell , 值为 git 安装目录中的 \bin\bash.exe
5. 启动 OpenSSH 服务
打开 cmd 运行 services.msc, 打开服务列表
创建仓库
选定一个目录作为 git 仓库, 在 gitbash 中执行命令
cd ~
mkdir gitrepo
cd gitrepo
git init --bare test.git
仓库创建完成后, 在工作目录中像以往开发一样使用 git 即可, 先进行克隆仓库
``` shell
git clone xx@127.0.0.1:~/gitrepo/test.git
```
注意 xx@127.0.0.1:~/gitrepo/test.git 各项
xx -> 对应当前 windows 系统用户
~/gitrepo/test.git -> 仓库所在文件路径
密码 -> 对应当前 xx 系统用户登录密码
参考资料
[Windows安装OpenSSH服务](https://www.cnblogs.com/herui1991/p/12376841.html)
[win10_git_server](https://gitee.com/wag173/win10_git_server)
[Git 服务器搭建](https://www.runoob.com/git/git-server.html)