Git 远程分支

发布于 2024-11-14 14:03:27 字数 504 浏览 2 评论 0原文

我目前使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟凡古楼 2024-11-21 14:03:27

首先:您不需要为软件的每个版本都有自己的存储库。如果你发布了,创建一个标签就足够了。引用此标签,您可以随时返回到已发布的版本。

如果您有一个中央存储库,允许两个开发人员中的每一个开发人员推送到该存储库,那么您必须将该存储库设为裸存储库(就像您引用的问题建议中接受的答案一样)。

裸存储库没有签出的工作副本,因此您始终可以推送到它们(至少只要您之前获取了最新版本)。

但你的场景听起来有点不同:例如,如果你有两台计算机,每台计算机都带有一个工作副本,并且想要在这两个盒子之间推送/拉取,那么解决方案是拥有一个仅在推送到 master 时使用的分支从另一台计算机。

以下工作流程(假设您要将分支 myfeature 的更改从 notebook 推送到当前拥有分支 myfeature 的远程 desktop code> 签出:

桌面 上:

git checkout -b temp

然后,在 笔记本 上:

git push desktop myfeature:myfeature

返回 桌面

git checkout myfeature
git branch -D temp 

另一种选择(在两个开发人员的情况下) (爱丽丝和鲍勃)在同一个分支工作)将是– 如果 Bob 想从 alice 获取最新版本的 myfeature – 他会从 alice 中拉取更改,而不是让她推送她的更改假设 alice 的计算机在 bob 的存储库中配置为远程 alice,并且 bob 当前已签出 myfeature 分支,

则执行此操作

git pull alice

如果 alice/myfeature 。代码>被配置为其 myfeature 分支的跟踪分支(使用 gitbranch --set-upstream myfeature alice/myfeature 设置)

git fetch alice
git merge 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 from notebook to the remote desktop that has currently the branch myfeature checked out:

On desktop:

git checkout -b temp

Then, on notebook:

git push desktop myfeature:myfeature

Back on desktop:

git checkout myfeature
git branch -D temp 

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 remote alice in bob's repo and bob has currently checked out the myfeature branch.

Either bob does

git pull alice

if alice/myfeature is configured as tracking branch for his myfeature branch (set it with git branch --set-upstream myfeature alice/myfeature). Or

git fetch alice
git merge alice/myfeature

if alice's myfeature branch is not configured as tracking branch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文