如何在我的 dev git 分支中跟踪 origin/master

发布于 2024-12-28 04:40:56 字数 1211 浏览 0 评论 0原文

我是 git 新手,我想知道如何解决一个非常基本的场景。我在 stackoverflow 上读了很多关于 git 的帖子,但仍然找不到答案。

我们有一个每个人都在处理的 origin/master 远程分支。 我有一个想要实现的功能 A,可能需要时间来开发。与此同时,人们可能会向 origin/master 签入代码。

考虑到以下需求,我的工作流程会是什么样子以及我应该如何设置我的 git 分支:

  1. 我希望能够将代码更改提交到我的分支并将它们推送到我们的远程分支服务器,这样我就不会在计算机损坏时丢失更改。

  2. 我想让我的分支与主分支保持最新。

  3. 我想尽量减少定期合并。我喜欢 git rebase 的概念,所以我想最大限度地利用它,从而实现快进合并。

  4. 在某些时候,我们必须将我的分支 FeatureA 合并到 origin/master 中。

    强>

总结:

如何设置一个从origin/master拉取但推送到origin/MY-的分支分支?

我的工作流程会是什么样子?

更新:

谢谢@will-pragnell!你的解决方案和下面的有什么区别。

github上的此页面建议:

https://github.com/diaspora/diaspora/wiki/Git -工作流程

为了从开发主干获取最新更新,请执行一次性设置,通过输入以下命令将主 GitHub 存储库建立为远程:

$ git remote add upstream git://github.com/diaspora/diaspora.git
$ git fetch upstream
$ git checkout master
$ git rebase upstream/master
$ git checkout 100-retweet-bugfix

[确保所有内容都根据需要在分支中提交]

$ git rebase master

I am new to git and I would like to know how to tackle a very basic scenario. I read so many posts on stackoverflow about git but still can't figure out the answer.

We have an origin/master remote branch that everybody is working on.
I have a featureA that I want to implement and might take time to develop. Meanwhile, people might be checking in code to the origin/master.

What would my workflow look like and how should I go about setting up my git branch, given the following needs:

  1. I want to be able to commit code changes to my branch and push them to a remote branch on our server so I don't loose the changes in case my computer is fried.

  2. I want to keep my branch up-to-date with the master branch.

  3. I want to minimize regular merges. I like to concept of git rebase so I would like to maximize its use and hence fast-forward merges.

  4. At some point we will have to merge my branch FeatureA into origin/master.

Summarizing:

How do I setup a branch that pulls from origin/master but pushes to origin/MY-BRANCH?

What would my workflow look like?

UPDATE:

Thank you @will-pragnell! What is the difference between your solution and the following.

This page on github suggest:

https://github.com/diaspora/diaspora/wiki/Git-Workflow

In order to get the latest updates from the development trunk do a one-time setup to establish the main GitHub repo as a remote by entering:

$ git remote add upstream git://github.com/diaspora/diaspora.git
$ git fetch upstream
$ git checkout master
$ git rebase upstream/master
$ git checkout 100-retweet-bugfix

[make sure all is committed as necessary in branch]

$ git rebase master

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

双马尾 2025-01-04 04:40:56

您可能不想要一个从 master 拉取并推送到您自己的分支的分支。您想要的是从 master 拉取到本地 master,在本地处理变基,然后推送到您自己的远程分支以获取该功能。这是一个相当标准的工作流程,为您提供完全的控制和最少量的合并。就我个人而言,我会这样做:

创建一个新的本地分支

git checkout -b myFeature

将其推送到新的远程分支(请参阅 这个 stackoverflow Question 如果您需要有关此步骤的更多信息)

git push origin myFeature

现在您可以在 myFeature 分支上愉快地工作,在需要时使用上述命令进行推送,而不会弄乱 master分支。当您需要获取其他人在 master 上完成的提交时,您可以这样做:

git checkout master
git pull (this will just fast-forward if you don't make any local changes to master)
git checkout myFeature
git rebase master

当您的功能完成后,您可以将您的分支合并或变基回 master,以便其他人获得您的新功能。像这样:

git checkout master
git merge myFeature
git push origin master

You probably don't want a branch that pulls from master and pushes to your own branch. What you want is to pull from master on to your local master, handle rebasing locally, and then push to your own remote branch for the feature. This is a fairly standard workflow and gives you complete control and a minimal amount of merging. Personally I would do it like this:

Create a new local branch

git checkout -b myFeature

Push that to a new remote branch (see this stackoverflow question if you need more info on this step)

git push origin myFeature

Now you can work away hapily on the myFeature branch, pushing using the above command when you need to without messing up the master branch. When you need to get hold of commits that others have done on master, you can do so like this:

git checkout master
git pull (this will just fast-forward if you don't make any local changes to master)
git checkout myFeature
git rebase master

When your feature is finished, you can the merge or rebase your branch back in to master so that everyone else gets your new feature. Like this:

git checkout master
git merge myFeature
git push origin master
来世叙缘 2025-01-04 04:40:56

git checkout -b FeatureA(创建并签出分支)
git push origin FeatureA(将新创建的分支推送到origin)

在新分支FeatureA上工作。您不希望频繁合并,然后在

git rebase origin  

将来每当您想要合并到 master 时重新设置基准。

git checkout master  
git merge FeatureA  
git push origin master  

git checkout -b FeatureA ( create and checkout branch )
git push origin FeatureA ( push your newly created branch to origin )

Work on new branch FeatureA. You do not want frequent merges then to rebase

git rebase origin  

In future whenever you want to merge into master.

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