git clone 从本地到远程 [英] git clone from local to remote

查看:29
本文介绍了git clone 从本地到远程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

目前,当我们创建一个新网站时,我们基本上是在本地克隆我们的 CMS,配置它,然后我们在中央存储库和网络服务器上克隆它(hg clone .ssh://account@server/www代码>).这样我们就可以即时访问推/拉优点.

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.

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

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

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

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?

推荐答案

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

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

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

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.

这篇关于git clone 从本地到远程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆