Git: local branchs tracks other local branch

戏子无情 提交于 2021-02-08 06:08:56

问题


I know that local branches can track remote branches, but there is also the possibility that a local branch tracks another local branch. What is a use-case for this?


回答1:


Real-world use:

I have an upstream repository, and a local branch tracking that remote. I start working on a major "feature" which will require a mess of changes to implement, but I don't yet want to expose the work upstream (potentially, ever).

So I create a local branch tracking my tracking branch. Now I have origin/master, master tracking that, and feature tracking master. So whenever origin/master is updated, I can keep origin/master up to date, and then apply my feature-specific changes on top of any uncommitted changes in the local master.

The reason why feature isn't directly tracking origin/master is that it may depend on work in the local master branch which isn't yet committed but isn't major enough to warrant its own feature branch.

This could also be useful for multiple independent features - basefeature tracks master, and subfeature tracks basefeature.




回答2:


Here's another one I actually needed:

We're working on a big project, with multiple teams working on multiple features. So, we have master, and feature-1, feature-2, etc. branches.

Let's say I'm currently working on feature-1. Working on a feature branch doesn't mean actually committing to that branch, rather branching off of that branch. Say I have been working on this feature for a couple months. I use git diff HEAD feature-1 a lot and other commands that involve the feature branch I'm working on.

Two months later, I started working on another branch. Now I have to be careful when running commands to use the new feature branch name feature-3, so to speak.

Wouldn't it be easier to have a branch active-feature that points to the feature branch I'm currently working on? I mean, I'm working on feature-1 and I can easily run then git diff HEAD active-feature. When I'm working on another feature, I need only to set active-feature to the new feature branch, and I can easily from thereafter use active-feature which boils down to the new feature branch.



来源:https://stackoverflow.com/questions/9266286/git-local-branchs-tracks-other-local-branch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!