2010-05-22 52 views
53

我的笔记本电脑上有一个本地Git存储库安装程序。我想推到我的桌面。如何将本地Git存储库推送到另一台计算机?

我该怎么做?

+4

git应该在superusers.com – vodkhang 2010-05-22 12:18:11

+1

你看了man page吗?键入'git help push'? – crazyscot 2010-05-22 12:28:17

+10

@vodkhang:不,它不应该超级用户。它是开发人员工具箱及其编程环境的重要组成部分。 – VonC 2010-05-22 12:47:04

回答

49

如果您可以访问到共享目录下,你可以(见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 

这将创建一个bare repo,在本地回购为“桌面”引用。
既然是裸露的,你可以(如果需要的话,以及来自它拉)推到它

git push desktop 

随着ProGit book mentions,混帐不支持的文件协议:

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

+0

'git push desktop'意味着将'从'笔记本电脑'推送到'桌面。一个'裸'回购绝对不是这个需要。 – Timo 2017-11-15 10:23:44

+0

@Timo是的,自2015年以来,非裸回购是可能的:https:// stackoverflow。com/a/30030236/6309 – VonC 2017-11-15 10:27:47

5

这是我写的脚本来做这件事。该脚本处理的新的git回购

  1. 我所有的常规的初始化将创建的.gitignore文件
  2. 初始化git的
  3. 在服务器上创建裸git仓库
  4. 树立本地的git回购推到远程回购

http://gist.github.com/410050

你一定要修改它适合你的任何设置,特别是如果你正在处理Windows笔记本电脑/台式机。

以下是完整的脚本:

#!/bin/bash 
# Create Git Repository 
# created by Jim Kubicek, 2009 
# [email protected] 
# 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 [email protected]$REPADDRESS:$REPLOCATION/ 
rm -rf $TEMPREP 

# Set up the origin for the project 
echo "Linking current repository to remote repository" 
git remote add origin [email protected]$REPADDRESS:$REPLOCATION/$REPNAME.git/ 
+2

我会建议在你的答案中全面复制你的脚本(因为它不是太大)。一旦堆栈溢出发布下一个cc-wiki转储(http://blog.stackoverflow.com/2009/06/stack-overflow-creative-commons-data-dump/),您确定此脚本将*始终*可用。否则,+1 – VonC 2010-05-22 12:59:42

2

最简单的(不是最好的)方法是通过局域网共享资源库目录,并使用Gi​​t的file://协议(见man git)。

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

相关问题