git克隆从本地到远程 [英] git clone from local to remote
问题描述
我们正在从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,然后将其克隆到中央repo和网络服务器( 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一样, ve遵循以下说明: http://caiustheory.com/automatically- deploying-website-from-remote-git-repository ,但是我想将.git目录保存在网站根目录中,就像Mercurial一样(它由Apache配置保护,我不能导出GIT_DIR对于所有帐户,因为有些拥有多个网站/ repos)。
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).
是否可以基本相同的设置,而不会将工作目录与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 --bare
或 scp
您当地的 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
当然,您将在此步骤之后运行上方的remote / push命令。在执行此操作后,您可能需要检出特定的分支,以便服务器上的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克隆从本地到远程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!