如何在本地网络上设置 Git?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28827831/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to setup Git on local network?
提问by Piyush
I downloaded Git setup and trying to setup for computers in my network. I searched for the process but I found it for to host code on line on github.com. I found a few links but there is not the whole process.
我下载了 Git 安装程序并尝试为我网络中的计算机进行设置。我搜索了这个过程,但我发现它用于在 github.com 上在线托管代码。我找到了一些链接,但没有整个过程。
I am aware for how to push and pull.
我知道如何推和拉。
采纳答案by JoyTree
To create a new repository
创建新存储库
- Create directory using git bash or create manually
User following commands to create repository
cd /repo/path/projectname.git git init --bare
After initialize directory share the directory and grant all permission to local group
- 使用 git bash 创建目录或手动创建
用户按照命令创建存储库
cd /repo/path/projectname.git git init --bare
初始化目录后共享目录并将所有权限授予本地组
To create a local workspace
创建本地工作区
Create another local repository for local user or other computer use following commands in same order
cd ~/workspace/local/path git init git clone user@gitserver:/path/to/your/folder git add origin repo/path git add . git status git commit
为本地用户或其他计算机按相同顺序使用以下命令创建另一个本地存储库
cd ~/workspace/local/path git init git clone user@gitserver:/path/to/your/folder git add origin repo/path git add . git status git commit
回答by JJ Brown
If you're asking about how to connect to a repository hosted by another computer on the same network, take a look at this StackOverflow thread.
如果您询问如何连接到同一网络上另一台计算机托管的存储库,请查看此 StackOverflow 线程。
Basically, you'll want to use git daemon. If you just need to set up a single repository, that's one line from each machine:
基本上,您需要使用git daemon。如果您只需要设置一个存储库,那么每台机器都有一行:
Server:
服务器:
git daemon --base-path=/path/to/repo --export-all
Client:
客户:
git remote add LocalServerName git://<serveraddress>/
or
或者
git clone git://<serveraddress>/
where <serveraddress>
is some reference to that machine (IPv4, IPv6, .local, etc.). You can also specify --verbose for the daemon
command for more detailed output.
哪里<serveraddress>
是对该机器的一些引用(IPv4、IPv6、.local 等)。您还可以为daemon
命令指定 --verbose 以获得更详细的输出。
I think, also, you could have --base-path
point to a folder with many repositories, and that would let you specify which project you wanted on the client-side like so:
我认为,您还可以--base-path
指向一个包含许多存储库的文件夹,这样您就可以在客户端指定想要的项目,如下所示:
git daemon --base-path=/path/to/all/repos
git remote add ServerName git://<serveraddress>/MyProject/
Be advised: using --export-all will let any computer on the network pull from your repo.
请注意:使用 --export-all 将使网络上的任何计算机从您的存储库中提取。
回答by Jan
You have to create a repository on the server side. Go to the folder which should be the repository and execute:
您必须在服务器端创建一个存储库。转到应该是存储库的文件夹并执行:
git init --bare
Then you have to clone the repository on your client with:
然后,您必须使用以下命令克隆客户端上的存储库:
git clone user@gitserver:/path/to/your/folder
Watch thisfor further information.
观看此内容以获取更多信息。
回答by AminRostami
It is just easy as 1, 2, 3, 4:
就像 1、2、3、4 一样简单:
1) Go to folder, where you want to initialize server(e.g: c:\temp
).
1) 转到要初始化服务器的文件夹(例如:)c:\temp
。
2) Open git bash
in this folder.
2)git bash
在此文件夹中打开。
3) Type:
3) 类型:
git init projectName --bare // e.g => git init test --bare
well,You've just set up your server!
好吧,您刚刚设置了服务器!
4) Choose where you want to initialize client repository and open git bash
there.
4) 选择要初始化客户端存储库的位置并git bash
在那里打开。
Type:
类型:
git clone path/projectName // e.g => git clone c:/temp/test
IMPORTANT! DO NOT FORGET TO CHANGE BACKSLASH (
\
) IN THE PATH TO DIRECT SLASH(/
).
重要的!不要忘记
\
在直接斜线 ( ) 的路径中更改反斜线(/
)。
You can use this repository as usual and open it with your favorite git client.
你可以像往常一样使用这个存储库,并用你最喜欢的 git 客户端打开它。
connect to this server from another computer in local network:
从本地网络中的另一台计算机连接到此服务器:
(in windows 7) Firstly go to Control Panel > Network And Sharing Center > Change advanced sharing settings. Tick turn on network discovery.
(在 Windows 7 中)首先进入控制面板 > 网络和共享中心 > 更改高级共享设置。勾选打开网络发现。
Then go to folder where you have set up server and share it with users that you want to give permission for accessing it.
然后转到您设置服务器的文件夹并与您要授予访问权限的用户共享。
then Type:
然后输入:
git clone //ip/projectName // e.g => git clone //192.168.11.125/test
I hope is useful.
我希望有用。