繁体   English   中英

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

[英]How to push a local Git repository to another computer?

我的笔记本电脑上有一个本地Git存储库设置。 我想把它推到我的桌面。

我怎样才能做到这一点?

如果您可以访问共享目录,则可以(请参阅git clonegit 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

这将创建一个裸仓库 ,在您的本地仓库中称为“桌面”。
由于它是裸露的,你可以推动它(如果需要也可以从中拉出)

git push desktop

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

最基本的是本地协议,其中远程存储库位于磁盘上的另一个目录中。
如果团队中的每个人都可以访问共享文件系统(如NFS挂载),或者每个人都登录到同一台计算机的可能性较小,则通常会使用此方法。

这是我写的一个脚本来做这件事。 该脚本处理我对git repos的所有常规初始化

  1. 创建.gitignore文件
  2. 初始化.git
  3. 在服务器上创建裸git仓库
  4. 设置本地git仓库以推送到该远程仓库

http://gist.github.com/410050

你肯定必须修改它以适应你所拥有的任何设置,特别是如果你正在处理Windows笔记本电脑/台式机。

这是完整的脚本:

#!/bin/bash
# Create Git Repository
# created by Jim Kubicek, 2009
# jimkubicek@gmail.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/

最简单(不是最好的)方法是通过LAN共享存储库目录,并使用git的file:// protocol(参见man git )。

对我来说,最好的方法是使用gitolite (有关详细说明,请参阅gitolite docs )。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM