Git 远程分支
我目前使用 Git 设置了一个中央裸存储库,两个开发人员可以通过远程存储库访问该存储库。当我创建一个分支,然后尝试将该分支从远程存储库推送到中央裸存储库时,我遇到了一个问题,类似于 这篇文章。
我读过跟踪分支是执行此操作的最佳方法,但是 使用 Git 进行版本控制我正在阅读的书说,由于跟踪分支旨在跟踪另一个存储库的更改,因此它们不应该用于合并和提交。
根据我当前的设置,处理不同分支的最佳方法是什么?
我一直打算为软件的每个版本/发行版建立一个分支,但似乎最简单的方法是为每个版本/发行版创建一个单独的存储库。
I currently have Git setup with a central bare repository which is accessed by two developers via remote repositories. I've hit on a problem when I've created a branch and then tried to push that branch from a remote repository to the central bare respository, similiar to that in this post.
I've read that tracking branches were the best way to do this, but the Version Control with Git book that I'm reading says that as tracking branches are designed to follow the changes from another repository that they shouldn't be used for merges and commits.
Based on my current set up, what's the best way to handle different branches?
I had been intending to have a branch for each version / release of the software but it seems that the easiest way would be to create a separate repositories for each version / release.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先:您不需要为软件的每个版本都有自己的存储库。如果你发布了,创建一个标签就足够了。引用此标签,您可以随时返回到已发布的版本。
如果您有一个中央存储库,允许两个开发人员中的每一个开发人员推送到该存储库,那么您必须将该存储库设为裸存储库(就像您引用的问题建议中接受的答案一样)。
裸存储库没有签出的工作副本,因此您始终可以推送到它们(至少只要您之前获取了最新版本)。
但你的场景听起来有点不同:例如,如果你有两台计算机,每台计算机都带有一个工作副本,并且想要在这两个盒子之间推送/拉取,那么解决方案是拥有一个仅在推送到 master 时使用的分支从另一台计算机。
以下工作流程(假设您要将分支
myfeature
的更改从notebook
推送到当前拥有分支myfeature
的远程desktop
code> 签出:在
桌面
上:然后,在
笔记本
上:返回
桌面
:。
另一种选择(在两个开发人员的情况下) (爱丽丝和鲍勃)在同一个分支工作)将是– 如果 Bob 想从 alice 获取最新版本的
myfeature
– 他会从 alice 中拉取更改,而不是让她推送她的更改假设 alice 的计算机在 bob 的存储库中配置为远程alice
,并且 bob 当前已签出myfeature
分支,则执行此操作
如果
alice/myfeature
。代码>被配置为其myfeature
分支的跟踪分支(使用gitbranch --set-upstream myfeature alice/myfeature
设置)。 > 分支未配置为跟踪分支。
First of all: you won't need an own repo for each version of your software. If you release, create a tag and that's all you need. Referencing this tag, you can always go back to the released version.
If you have a central repo where each of your two developers shall be allowed to push to, then you'll have to make that repo a bare repo (like the accepted answer in your referenced question recommends).
Bare repositories have no checked out working copy, therefore you can always push to them (at least as long as you fetched the latest version before).
But your scenario sounds a little different: if you have, for example, two computers where each one carries a working copy and want to push/pull between these two boxes, the solution is to have a branch that is only used while pushing to master from the other computer.
Following workflow (assuming you want to push changes of branch
myfeature
fromnotebook
to the remotedesktop
that has currently the branchmyfeature
checked out:On
desktop
:Then, on
notebook
:Back on
desktop
:That's it.
Another alternative (in the case of two developers (alice and bob) working on the same branch) would be that – if bob wants to get the latest version of
myfeature
from alice – he pulls the changes from alice instead of letting her push her changes into his repo. Assuming alice's computer is configured as remotealice
in bob's repo and bob has currently checked out themyfeature
branch.Either bob does
if
alice/myfeature
is configured as tracking branch for hismyfeature
branch (set it withgit branch --set-upstream myfeature alice/myfeature
). Orif alice's
myfeature
branch is not configured as tracking branch.