简体   繁体   English

我应该如何设置我的Git存储库以能够在两个地方同时推送并仍具有工作目录?

[英]How should I setup my Git repositories to be able to push and still have a working directory at both places?

I have a personal laptop and a development box and want a setup with following things in mind: 我有一台个人笔记本电脑和一个开发箱,想要进行以下设置:

  1. I want to have my code working on both machines. 我想让我的代码在两台机器上都能工作。 (That means I cannot have --bare repo.) (这意味着我不能拥有--bare 。)
  2. I want to develop on my laptop. 我想在笔记本电脑上进行开发。
  3. I want to push to dev box from time to time. 我想不时推送到开发箱。
  4. This is mainly for web development. 这主要用于Web开发。

I tried initializing a Git repo with code on dev box and cloned in on my laptop. 我尝试使用开发箱上的代码初始化Git存储库,然后克隆到笔记本电脑上。 I could not push changes to dev box though. 我无法将更改推送到开发箱。 It gives me the error that I am pushing to a non-bare repo. 它给了我我推向一个非裸仓库的错误。

Then I tried --bare repo and it worked, but then I cannot run the code sitting on dev box. 然后我尝试了--bare repo并成功了,但是后来我无法运行位于开发箱上的代码。 (Or can I?) (或者我可以吗?)

Any ideas on how to achieve this kind of setup? 关于如何实现这种设置的任何想法?

One way to solve this is to create a third repo (that you can think of as the "main" repository) that is --bare . 解决此问题的一种方法是创建第三个仓库--bare (您可以将其视为“主要”存储库)。 To share changes, you can push to the bare repository from one machine and pull from the other. 要共享更改,您可以从一台计算机推送到裸存储库,然后从另一台计算机提取。

If you put this bare repo on the web box, then you can set up a post-commit hook to automatically extract the files from the main repo to the (non-bare) repo that's used by the web server. 如果将此裸仓库放置在Web框上,则可以设置提交后钩子,以将文件从主仓库自动提取到Web服务器使用的(非裸仓库)仓库。

I usually don't set up such a post-commit hook, but my workflow is generally: 我通常不设置这样的提交后挂钩,但是我的工作流程通常是:

  • make change locally (laptop in your case) 在本地进行更改(您的笔记本电脑)
  • ensure it works in test environment 确保它在测试环境中工作
  • commit 承诺
  • push to bare repo 推送到裸仓库
  • on web server, pull from bare repo into working dir 在Web服务器上,从裸仓库拉入工作目录

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何设置我的.git / config以便能够从多个远程存储库推送/拉出? - How can I setup my .git/config to be able to push to / pull from multiple remote repositories? 我如何才能将“git push”推送到本地存储库? - How can I have it to where “git push” pushes to local repositories? 如何在Eclipse中为Android开发设置我的Git存储库? - How do I setup my Git repositories for Android development in Eclipse? 我应该如何使用我的.NET解决方案构建我的Git存储库? - How should I structure my Git repositories with my .NET Solution? 当两者都在防火墙/ NATs / ...后面时,如何在git存储库之间推/拉? - How can I push/pull between git repositories when both are behind firewalls/NATs/…? 如何使用git将不同的README.md从一个工作目录推送到两个存储库 - How to push different README.md from one working directory to two repositories using git 如何根据目录结构正确设置Git和GitHub存储库 - How to correctly setup Git and GitHub repositories based on directory structure 我应该如何将我的 git 存储库下载到新设置的 PC? - How should I download my git repo to newly setup PC? 如何使用 git 从我的 PC 推送到多个 GitHub 帐户? (不同的存储库) - How can I push to multiple GitHub accounts from my PC using git? (different repositories) 如何设置我的git存储库以便轻松地在Visual Studio中重用项目 - How do I set up my git repositories to easily be able to reuse projects in Visual Studio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM