如何将本地Git仓库推送到另一台电脑上?

发布于 2024-09-03 02:19:45 字数 61 浏览 5 评论 0原文

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

我怎样才能做到这一点?

I have a local Git repository setup on my laptop. I would like to push it to my desktop.

How can I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

嘿看小鸭子会跑 2024-09-10 02:19:45

如果您有权访问共享目录,则可以(请参阅 git clone< /a> 和 git 远程 ):

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 安装),或者在每个人都登录到同一台计算机的不太可能的情况下,通常会使用此方法。

If you have access to a shared directory, you can (see git clone and 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

That will create a bare repo, referenced in your local repo as "desktop".
Since it is bare, you can push to it (as well as pull from it if needed)

git push desktop

As the ProGit book mentions, git does support the file protocol:

The most basic is the Local protocol, in which the remote repository is in another directory on disk.
This is often used if everyone on your team has access to a shared filesystem such as an NFS mount, or in the less likely case that everyone logs in to the same computer.

秋日私语 2024-09-10 02:19:45

这是我为完成此任务而编写的脚本。该脚本处理我对新 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 $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/

Here's a script that I wrote to do just this thing. The script handles all my usual initialization of new git repos

  1. creates .gitignore file
  2. initializes .git
  3. creates the bare git repo on the server
  4. sets up the local git repo to push to that remote repo

http://gist.github.com/410050

You'll definitely have to modify it to suit whatever setup you've got, especially if you're dealing with Windows laptop/desktop.

Here is the full script:

#!/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 $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/
仅此而已 2024-09-10 02:19:45

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

对我来说,最好的方法是使用 gitolite (参见 gitolite 文档 了解详细说明)。

The easiest (not the best) way is to share the repository directory via LAN, and use git's file:// protocol (see man git).

For me, the best way is to use gitolite (see gitolite docs for detailed instructions).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文