git 从本地克隆到远程

发布于 2024-10-01 12:02:28 字数 685 浏览 4 评论 0原文

我们的工作流程正在从 Mercurial 迁移到 Git,但我有两个小问题。

首先,是否可以将本地存储库直接“克隆”到空的远程(ssh)目录中?

目前,当我们创建新网站时,我们基本上在本地克隆 CMS,对其进行配置,然后将其克隆到中央存储库和网络服务器上 (hg clone .ssh://account@server/www) 。这样我们就可以立即获得推/拉的好处。

这就引出了第二个问题,远程部署。

目前使用 Mercurial,我在远程存储库中有一个简单的钩子,当收到变更集时,它会执行 hg up

要对 Git 执行相同操作,我按照此处的说明进行操作: http:// /caiustheory.com/automatically-deploying-website-from-remote-git-repository 但我想将 .git 目录保留在网站根目录中,就像 Mercurial 的情况一样(它受 Apache 配置保护)我无法为所有帐户导出 GIT_DIR,因为有些帐户有多个网站/存储库)。

是否可以在不将工作目录与存储库分开的情况下拥有基本相同的设置?

We're in the process of migrating from Mercurial to Git for our workflow and I have two minor issues.

First, is it possible to "clone" a local repository directly into an empty remote (ssh) dir?

Currently when we create a new website we basically clone our CMS locally, configure it and then we clone it on the central repo and on the webserver (hg clone . ssh://account@server/www). That way we have instant access to push/pull goodness.

This brings me to the second issue, remote deployment.

Currently with Mercurial, I have a simple hooks in the remote repos that execute hg up when a changeset is received.

To do the same with Git I've followed the instructions here: http://caiustheory.com/automatically-deploying-website-from-remote-git-repository but I'd like to keep the .git directory in the website root as it is the case with Mercurial (it's protected by Apache config and I can't export GIT_DIR for all accounts as some have more than one website/repos).

Is it possible to have basically the same setup without separating the working dir from the repos?

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

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

发布评论

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

评论(6

余生共白头 2024-10-08 12:02:28

回答你的第一个问题,是的,你可以。假设远程目录是 ssh://user@host/home/user/repo 。这必须是一个 git 存储库,使用 git init --barescp 本地 repo.git 创建它(可以使用 >git clone) 目录到远程。然后执行以下操作:

git remote add origin ssh://user@host/home/user/repo
git push --all origin

这会将所有本地现有分支推送到远程存储库。

要解决下一个问题,您应该能够使用一组不同的命令来完成相同的操作。尝试这些:

$ cd /var/www  # or wherever
$ mkdir somesite
$ cd somesite/
$ git init
$ git --bare update-server-info
$ git config receive.denycurrentbranch ignore
$ cat > hooks/post-receive
#!/bin/sh
git checkout -f
^D
$ chmod +x hooks/post-receive

当然,在此步骤之后运行上面的远程/推送命令。执行此操作后,您可能必须检查特定分支,以便服务器上的“somesite”克隆实际上知道要遵循哪个分支。从那时起,推送到该存储库应该会触发该分支的重新签出。

To answer your first question, yes, you can. Suppose the remote directory is ssh://user@host/home/user/repo. This must be a git repository, create that with git init --bare or scp your local repo.git (can be created with git clone) directory to remote. Then do:

git remote add origin ssh://user@host/home/user/repo
git push --all origin

This will push all locally-existing branches to the remote repository.

To get to your next question, you should be able to do the same thing by using a different set of commands. Try these:

$ cd /var/www  # or wherever
$ mkdir somesite
$ cd somesite/
$ git init
$ git --bare update-server-info
$ git config receive.denycurrentbranch ignore
$ cat > hooks/post-receive
#!/bin/sh
git checkout -f
^D
$ chmod +x hooks/post-receive

You would, of course, run the remote/push commands above after this step. You may have to check out a specific branch after doing so, so that the "somesite" clone on the server actually knows which branch to follow. From then on out, pushing to that repository should trigger a re-checkout of that branch.

夕嗳→ 2024-10-08 12:02:28

我最近也遇到了这个问题,解决方法如下:

在远程服务器上:

1:创建一个名为/tmp/bare的目录
2:更改到该目录
3: 执行 git init --bare

在本地计算机上:

1: 更改到您的 git 项目目录
2:git远程添加裸机 ssh://user@server/tmp/bare
3: git Push --全部裸露
4: git Remote remove bare

在远程服务器上:

1: git clone /tmp/bare /path/to/your/clone

在本地计算机上:

1: git remote add origin ssh://user@server/ path/to/your/clone

这有点复杂,但它可以工作,并且不需要设置任何奇怪的标志或指示 git 覆盖其默认行为。因此它是相当安全的。

I also ran into this issue recently and solved it as follows:

On remote server:

1: Create a directory named /tmp/bare
2: Change to that directory
3: Execute git init --bare

On local machine:

1: Change to your git project directory
2: git remote add bare ssh://user@server/tmp/bare
3: git push --all bare
4: git remote remove bare

On remote server:

1: git clone /tmp/bare /path/to/your/clone

On local machine:

1: git remote add origin ssh://user@server/path/to/your/clone

This is a little involved, but it works and does not require setting any weird flags or instructing git to override its default behaviours. It is hence quite safe.

偏爱你一生 2024-10-08 12:02:28

这个答案很好,但我无法让它为我工作。此链接中的以下代码执行了 http://thelucid.com/2008/12/02/git-setting-up-a-remote-repository-and-doing-an-initial-push/。在远程运行上

mkdir my_project.git
cd my_project.git
git init --bare
git-update-server-info # If planning to serve via HTTP

在本地已至少运行一次提交的现有存储库上,

git remote add origin [email protected]:my_project.git
git push -u origin master

我希望这可以帮助任何对其他答案有问题的人。

This answer is good but I was not able to get it to work for me. The following code from this link did http://thelucid.com/2008/12/02/git-setting-up-a-remote-repository-and-doing-an-initial-push/. On the remote run

mkdir my_project.git
cd my_project.git
git init --bare
git-update-server-info # If planning to serve via HTTP

Locally on an existing repository that already has at least one commit run

git remote add origin [email protected]:my_project.git
git push -u origin master

I hope this helps anyone that had problems with the other answer.

空心空情空意 2024-10-08 12:02:28

最简单的 git 相当于 hg clone 。 ssh://account@server/www 是:

rsync -avz . ssh://account@server/www/reponame

事实上,我已将此行添加到 ~/.bash_aliases 中以镜像任何位置的任何目录:

alias mirror="rsync -avz . ssh://account@server`pwd` --delete"

如果您碰巧位于 /dev 等特殊目录中,则可能会很危险或/bin。
当心。

Easiest git equivalent to hg clone . ssh://account@server/www is:

rsync -avz . ssh://account@server/www/reponame

In fact, I have added this line to ~/.bash_aliases to mirror any directory anywhere:

alias mirror="rsync -avz . ssh://account@server`pwd` --delete"

It could prove dangerous if you happen to be in a special directory like /dev or /bin.
Be careful.

时光是把杀猪刀 2024-10-08 12:02:28

我同意,并通过删除不匹配的文件来改进 presto8。

rsync -avz . ssh://account@server/www/reponame --delete

I agree with, and improve on presto8 by deleting unmatched files.

rsync -avz . ssh://account@server/www/reponame --delete
梦里泪两行 2024-10-08 12:02:28

只是为了给你一个替代方案,你可以使用:

git remote set-url origin git://other.url.here

如果你的本地 git 存储库指向另一个远程存储库,这些也可以工作

Just to give you an alternative, you can use:

git remote set-url origin git://other.url.here

These also work if your local git respository is pointing to another remote repository

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