如何将本地Git仓库推送到另一台计算机?

13 浏览
0 Comments

如何将本地Git仓库推送到另一台计算机?

我在笔记本电脑上设置了一个本地的Git仓库。我想把它推送到我的台式电脑上。

我该如何操作?

0
0 Comments

问题的出现原因:希望将本地的Git仓库推送到另一台计算机上,但不清楚如何实现。

解决方法:

1. 最简单的方法是通过局域网共享仓库目录,并使用Git的file://协议来进行推送。具体操作可以参考Git的官方文档中的man git部分。

2. 对我来说,最好的方法是使用gitolite。可以参考gitolite文档中的详细说明进行操作。

文章整理如下:

如何将本地Git仓库推送到另一台计算机?

推送本地Git仓库到其他计算机是一个常见的需求。下面介绍两种解决方法。

1. 通过局域网共享目录

最简单的方法是通过局域网共享Git仓库目录,并使用Git的file://协议进行推送。具体操作可以参考Git的官方文档中的man git部分。

2. 使用gitolite

对我来说,最好的方法是使用gitolite。gitolite是一个Git服务器管理工具,可以帮助管理多个Git仓库的访问权限。具体操作可以参考gitolite的文档中的详细说明。

希望以上方法能帮助你成功推送本地Git仓库到另一台计算机。

0
0 Comments

问题:如何将本地Git仓库推送到另一台计算机?

原因:需要将本地Git仓库推送到另一台计算机,以便在不同计算机之间共享代码和项目。

解决方法:可以使用下面的脚本来实现这个目标。这个脚本处理了所有常见的新建Git仓库的初始化工作。

1. 创建.gitignore文件

2. 初始化.git

3. 在服务器上创建裸仓库

4. 设置本地Git仓库以推送到远程仓库

完整的脚本如下:

#!/bin/bash
# Create Git Repository
# created by Jim Kubicek, 2009
# jimkubicek.com
# http://jimkubicek.com
# DESCRIPTION
# Create remote git repository from existing project
# this script needs to be run from within the project directory
# This script has been created on OS X, so YMMV
#######
# Parameters
REPLOGIN=#Login name
REPADDRESS=#Repo address
REPLOCATION=/Users/Shared/Development #Repo location
# The repo name defaults to the name of the current directory.
# This regex will accept foldernames with letters and a period.
# You'll have to edit it if you've got anything else in your folder names.
REPNAME=`pwd | egrep -o "/[a-zA-Z]+$" | egrep -o "[a-zA-Z\.]+"`
# If you have standard files/directories to be ignored
# add them here
echo "Creating .gitignore"
echo 'build/' >> .gitignore # The build directory should be ignored for Xcode projs
echo '.DS_Store' >> .gitignore # A good idea on OS X
# Create the git repo
echo "Initializing the repo"
git init
git add .
git commit -m "Initial commit"
# Copy the repo to the server
echo "Copying the git repo to the server $REPADDRESS"
TEMPREP="$REPNAME.git"
git clone --bare .git $TEMPREP
scp -r $TEMPREP $REPLOGIN@$REPADDRESS:$REPLOCATION/
rm -rf $TEMPREP
# Set up the origin for the project
echo "Linking current repository to remote repository"
git remote add origin $REPLOGIN@$REPADDRESS:$REPLOCATION/$REPNAME.git/

以上脚本可以根据实际情况进行修改,特别是如果使用的是Windows笔记本或台式机。

参考链接:[http://gist.github.com/410050](http://gist.github.com/410050)

0
0 Comments

问题的原因是用户想要将本地的Git仓库推送到另一台计算机上,但不清楚如何操作。解决方法是使用git clone和git remote命令将本地仓库复制到共享目录,并设置远程仓库。然后使用git push命令将代码推送到远程仓库。

文章内容如下:

如果您可以访问共享目录,可以使用git clone和git remote命令进行操作:

git clone --bare /path/to/your/laptop/repo /shared/path/to/desktop/repo.git

git remote add desktop /shared/path/to/desktop/repo.git

这将在共享目录中创建一个裸仓库,并在本地仓库中将其命名为"desktop"。

由于是裸仓库,您可以推送代码到它(如果需要,还可以从它拉取代码):

git push desktop

正如ProGit书中所提到的,git支持文件协议:

最基本的是"Local"协议,即远程仓库位于磁盘上的另一个目录中。

这通常用于团队中的每个人都可以访问共享文件系统(如NFS挂载),或者在每个人登录到同一台计算机的较少情况下使用。

git push desktop

表示从本地仓库推送到desktop。这种情况下不需要裸仓库。

是的,自2015年以来,非裸仓库是可行的:stackoverflow.com/a/30030236/6309

如果我没有访问共享目录怎么办?我想要做的是从我的本地仓库执行git clone . ssh://user:git/remoteRepo.git。或者只能登录到我的桌面电脑上并在那里创建(裸)仓库吗?

8年后,您可以使用SSH,考虑到Windows 10已经内置了OpenSSH服务器(bleepingcomputer.com/news/microsoft/…bleepingcomputer.com/news/microsoft/…

这里不需要Windows;OpenSSH在Linux上已经存在很长时间了。然而,git clone . ssh://user:git/remoteRepo.git会在名为ssh:/user:git/remoteRepo.git的子目录中创建一个本地仓库,而我想要一个远程仓库-这就是问题的关键。那么我如何通过ssh连接到远程机器,而不是创建一个名为ssh的目录。

您没有提到您的操作系统。您可以尝试使用以下URL:ssh://user/full/path/to/git/remoteRepo.git(不包含“:”符号)

抱歉,我在本地和远程都使用Linux。这个命令(完整命令为git clone . ssh://user/home/user/path/to/git/remoteRepo.git)在我的本地机器的当前目录下创建了一个子目录树./ssh:/user/home/user/path/to/git/remoteRepo.git

您使用的git版本是多少?我假设在远程桌面上,路径/home/user/path/to/git/remoteRepo.git是存在的。

让我们在聊天中继续讨论:chat.stackoverflow.com/rooms/185285/discussion-between-astrofloyd-and-vonc

0