如何用本机做一个局域网Git服务器

您所在的位置:网站首页 github作为服务器 如何用本机做一个局域网Git服务器

如何用本机做一个局域网Git服务器

2023-09-02 20:48| 来源: 网络整理| 查看: 265

1.新建中转仓

中转仓库其实是一个裸仓库,这个仓库文件夹里只有.git里的版本信息,没有代码。 所有工作者都只与中转仓库建立联系,这样冲突只会发生在中转仓库,各机本地代码不会冲突,从而最大程度上避免混乱。

具体操作:

打开 Git Bash Here

mkdir myrepo.git && cd myrepo.git git init --bare --shared git remote add orgin file:///D:/TestGit/myrepo.git git remote origin

显示结果为origin,表示我们操作成功且已经生效。

D:/TestGit/myrepo.git 表示我用来作为服务器的文件地址

然后将myrepo.git文件夹作为共享文件夹

2.构建本机克隆仓库

在设置中转仓库的机器上新建克隆仓库,可以修改代码并上传。

从中转仓将工程下载下来,并命名为 mylocalrepo_a.git

git clone file:///D:/TestGit/myrepo.git mylocalrepo_a.git cd mylocalrepo_a.git cat > README Hello World #输入 Ctrl + D 终止输入

修改之后保存并提交

git add . git commit -m "Init the test repo" git branch --unset-upstream git push -u origin --all 3.在其他机器同步仓库

在另外的机器上新建克隆仓库,通过ssh建立仓库之间的连接。可以用于拉取和上传更新。

通过ssh的方式需要知道中转仓库所在机器的用户名和IP地址,基本格式为git clone ssh://username@ipaddr/path/to/repo.git localrepo.git。主要步骤展示如下。

此时在其他电脑上“映射网络驱动”,将作为服务器的电脑的共享盘设置为映射网络驱动 Z:

git clone Z: mylocalrepo_d.git cd mylocalrepo_d.git git pull origin master cat >> README Great idea. #输入 Ctrl + D 终止输入 git add . git commit -m "Modification from machine d" git push origin master

或者用简单的方法

git clone Z: mylocalrepo_d.git git pull origin master #从中转仓将最新的代码下拉

然后直接用文本工具将文本中的文字更改,再将更改的同步到中转仓

git commit README -m "Motification machine d" git push origin master #将最新的代码上传到中转仓



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3