Git 工作流:在计算机之间共享代码而不推送到公共存储库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11419448/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git Workflow: Share code between computers without pushing to public repo
提问by s73v3r
I work at a company which uses Git for our version control. We're using a hosted repo service (Beanstalk) as our internal "public" (by that I mean accessible to the whole dev team) repo. I have two computers that I normally work on for writing code. I like using some of the history rewriting features of Git, specifically rebasing and amending commits, but I really don't like using them after I've pushed something to a published branch. Yet, I need to be able to share code between these two computers, and preferably no one else.
我在一家使用 Git 进行版本控制的公司工作。我们使用托管存储库服务 (Beanstalk) 作为我们的内部“公共”(我的意思是整个开发团队都可以访问)存储库。我有两台通常用来编写代码的计算机。我喜欢使用 Git 的一些历史重写功能,特别是重新定位和修改提交,但我真的不喜欢在将某些内容推送到已发布分支后使用它们。然而,我需要能够在这两台计算机之间共享代码,最好不要在其他计算机之间共享。
What I'd like is an easy way to share my code between the two computers, without having to share it with everyone else. I have considered Airdrop (both computers are Macs), and ssh. What would be the suggested way of achieving this, while taking advantage of git's distributed nature?
我想要的是一种在两台计算机之间共享我的代码的简单方法,而不必与其他人共享。我考虑过Airdrop(两台电脑都是Mac)和ssh。在利用 git 的分布式特性的同时,实现这一目标的建议方法是什么?
回答by fork0
You can push, fetch and pull between the machines freely assuming you have ssh access between them:
假设您在它们之间具有 ssh 访问权限,您可以在机器之间自由地推、取和拉:
git push computer2:projects/prog HEAD:tmp
or, if you are on computer2:
或者,如果您在计算机 2 上:
git pull computer1:projects/prog HEAD
or
或者
git fetch computer1:prj/prog branch1:t1
git fetch computer1:prj/prog branch2:t2
git merge t1 t2
or
或者
git fetch computer1:prj/prog branch1 branch2 branch3
git merge FETCH_HEAD
and so on... See git help fetch
for more examples.
等等...git help fetch
更多例子参见。
回答by prusswan
I don't see why you cannot create temp working branches that are clearly indicated as such on the remote repo, but if you want an alternative and both computers are connected by network and accessible via ssh, you could possibly set up either or both of them as additional remotes and push from one to the other in any direction. It may be confusing to get it right the first time though as you do not want to push to the wrong remote.
我不明白为什么你不能创建在远程仓库上明确指示的临时工作分支,但是如果你想要一个替代方案并且两台计算机都通过网络连接并且可以通过 ssh 访问,你可以设置其中一个或两个它们作为额外的遥控器,从一个方向推到另一个方向。第一次做对可能会令人困惑,因为您不想推送到错误的遥控器。
回答by rlc
You can run an instant git server on one of the machines, either using git-daemon or something like this: https://gist.github.com/1525217
您可以在其中一台机器上运行即时 git 服务器,使用 git-daemon 或类似的东西:https: //gist.github.com/1525217