如何在没有互联网连接的情况下在ubuntu上拉一个git存储库?

时间:2014-10-02 08:52:32

标签: git ubuntu offline git-pull

我想在我们公司的本地网络上使用Git,因为我的计算机无法访问互联网。我的朋友有一个互联网连接和一个ubuntu机器,他将一些源代码推送到Git,我需要在没有Internet连接的情况下拉它们,我也使用ubuntu 14.04。 另外,我使用以下命令设置了一个存储库:

git init --bare
编辑:两台机器都是ubuntu,对不起有误。

4 个答案:

答案 0 :(得分:3)

请你的朋友为git存储库创建一个Windows共享。

确保已安装

apt-get install cifs-utils

创建一个mount dir

$ mkdir ~/my_friends_repo

使用

安装远程共享
$ sudo mount -t cifs -o username=USERNAME,password=PASSWORD \
      //your_friends_ip_or_computer_name/NAME_OF_SHARE ~/my_friends_repo

现在你可以克隆它

git clone ~/my_friends_repo my_friends_repo_clone

或将其作为另一个远程存储库添加到现有存储库并提取其更改

git remote add my_friends_repo ~/my_friends_repo
git pull my_friends_repo master

答案 1 :(得分:2)

除了previous answer ...

您的朋友可以在他的Windows机器上使用git daemon来导出存储库

在Windows机器上执行git bash

git daemon --export-all --reuseaddr --verbose --enable=receive-pack --base-path=PATH_TO_THE_REPOSITORY

在你的ubuntu机器上,你可以克隆repo

git clone git://your_friends_ip_or_computer_name REPO_CLONE_NAME

或将其作为另一个远程存储库添加到现有存储库并提取其更改

git remote add my_friends_repo  git://your_friends_ip_or_computer_name
git pull my_friends_repo master


touch git-daemon-export-ok

答案 2 :(得分:1)

基本

git存储库不仅仅是一个盒子。您可以将代码放入其中(提交),您可以将内容的副本发送到另一个(远程)框(推送),然后您可以将内容从另一个框中提取到您自己的框中(拉)。

如果您的朋友将他的内容推送到互联网上的某个方框(例如github)并且您无法从主持人访问该位置,则此框对您的情况没有帮助。

您有几个选择:

  • 直接从您的朋友存储库中提取("框"他曾经推送到github。)
  • 请他直接将他的存储库推送给您的主机。
  • 在网络中的某个位置设置一些存储库。 (在这种情况下,他可以推送到该存储库,然后您可以从中获取它。)

使用中间存储库的解决方案

当你使用已经附带ssh的ubuntu时,也许最简单的解决方案是在你的盒子上设置一个新用户并在那里创建一个裸存储库。然后你就可以从你的朋友那里获得一个可以使用该用户推送到该存储库的地方。

你可以这样做:

sudo useradd -m gituser                     # create user
sudo -iu gituser git init --bare reponame   # create repository
sudo passwd gituser                         # set password for user

之后你的朋友可以使用git push gituser@yourhost/reponame推送到它。您可以使用git clone gituser@yourhost/reponame获取推送的内容。

使用git-daemon的解决方案

另一种方法是在朋友主机上使用git-daemon来为其存储库提供服务。在这种情况下,您可以直接从他的主机拉。在Windows上输入:

git daemon --base-path=PATH --export-all

其中"路径"是包含存储库的本地目录。在ubuntu上,您可以使用

访问该存储库
git clone git://friendshost/reponame

其中" friendshost"是您朋友主持人的主持人名称," reponame"是包含存储库的目录的名称。例如,如果存储库位于" C:\ some \ dir \ repo"那么" C:\ some \ dir"是PATH和" repo"是重新命名。)

答案 3 :(得分:-1)

这取决于你的朋友在他的git存储库所在的位置。

您可以在.gitconfig文件中指定远程起源的位置。 有关详细信息,请参阅此link