threads / discuss / 24699

workflow for working on feature branches and incrementally incorporating "master" changes

Subject: workflow for working on feature branches and incrementally incorporating "master" changes

## tl;dr

6 messages between Aug 10, 2010 and Aug 13, 2010.

replies: 5people: 5as markdown or json

Bradley Wagner· Aug 10, 2010, 20:20 UTC · lore

If you're working on a feature branch by yourself, what is a good workflow for keeping the branch in up-to-date with "master" as you're developing on the feature branch or is this unnecessary? Should you just wait until you want to officially integrate the feature branch into the "master"?

We were doing:

commit to local feature branch push to remote feature branch ... repeat.... rebase from master (occasionally) push to remote

but at this point the branches have diverged.

We're coming at this from SVN, so we might just be thinking about this the wrong way.

Thanks!
Ævar Arnfjörð Bjarmason· Aug 10, 2010, 21:02 UTC · re: Bradley Wagner · lore

Re: workflow for working on feature branches and incrementally incorporating "master" changes

On Tue, Aug 10, 2010 at 20:20, Bradley Wagner <bradley.wagner@hannonhill.com> wrote:

> We're coming at this from SVN, so we might just be thinking about this
> the wrong way.

What workflow did you use with SVN? Did it use branches? If so you could just use that.

Chris Mear· Aug 10, 2010, 22:05 UTC · re: Bradley Wagner · lore

Re: workflow for working on feature branches and incrementally incorporating "master" changes

On 10 August 2010 21:20, Bradley Wagner <bradley.wagner@hannonhill.com> wrote:
Show 18 quoted lines
> If you're working on a feature branch by yourself, what is a good
> workflow for keeping the branch in up-to-date with "master" as you're
> developing on the feature branch or is this unnecessary? Should you
> just wait until you want to officially integrate the feature branch
> into the "master"?
>
> We were doing:
>
> commit to local feature branch
> push to remote feature branch
> ... repeat....
> rebase from master (occasionally)
> push to remote
>
> but at this point the branches have diverged.
>
> We're coming at this from SVN, so we might just be thinking about this
> the wrong way.

Git's rebase feature is a *very* nice, clean way to keep a feature branch up to date with the master branch. But, as you've seen, rebasing can make things a bit confusing you need to push that feature branch to other people.

I've found that a good rule of thumb is to never rewrite (i.e. rebase) branches that have already been shared with others. Of course there's nothing impossible or fundamentally bad about pushing rewritten branches like this. But, unless people are expecting it to happen and know how to deal with it when they pull, it can cause confusion, particularly on teams that are just getting acquainted with Git.

Instead, if a feature branch is going to be shared with others, and it's going to be long-lived, then we keep it up-to-date by merging from master every now and again, rather than rebasing.

On the other hand, if I'm working on a feature branch by myself, and I haven't shared it with anyone yet, I frequently rebase against master to keep things clean. I also use interactive rebase a lot to tidy up commits. But as soon as I've shared my branch with the team, I no longer do any rebasing/rewriting.

If there are Git wizards on your team, it is true that they may find this an inflexible way of working. But I've found it to be a good compromise between ease of pulling and maintaining a clean commit history.

Chris
Joshua Shrader· Aug 10, 2010, 22:26 UTC · re: Chris Mear · lore

Re: workflow for working on feature branches and incrementally incorporating "master" changes

To elaborate on Chris's response, as an alternative to merging to feature from master repeatedly, you may want to take a look at git rerere. The "Discussion" section at http://www.kernel.org/pub/software/scm/git/docs/git-rerere.html explains a workflow where this feature is useful. You don't rebase, and so preserve where the feature originally branched, but you also avoid multiple merge commits from master that may clutter the commit history. Essentially, you do a merge, resolve any conflicts, and then back out of the merge with git reset --hard HEAD^. This removes the merge commit, but rerere remembers all of the conflicts that you resolved. When you repeat this process the next time, you won't have to re-resolve conflicts that you've already taken care of.

Essentially, the history looks like you've developed the feature in complete isolation of master, and fixed all of the conflicts at once during the only publicly visible merge commit from feature back to master. But what you've really done is solved the conflicts little by little, so the final merge isn't a huge pain in the *ss.

This is probably a more advanced use case, and so might not be the best approach to a team just getting their feet wet with Git, but still, it's a workflow that does what you're asking.

On Tue, Aug 10, 2010 at 6:05 PM, Chris Mear <chrismear@gmail.com> wrote:
Show 53 quoted lines
> On 10 August 2010 21:20, Bradley Wagner <bradley.wagner@hannonhill.com> wrote:
>> If you're working on a feature branch by yourself, what is a good
>> workflow for keeping the branch in up-to-date with "master" as you're
>> developing on the feature branch or is this unnecessary? Should you
>> just wait until you want to officially integrate the feature branch
>> into the "master"?
>>
>> We were doing:
>>
>> commit to local feature branch
>> push to remote feature branch
>> ... repeat....
>> rebase from master (occasionally)
>> push to remote
>>
>> but at this point the branches have diverged.
>>
>> We're coming at this from SVN, so we might just be thinking about this
>> the wrong way.
>
> Git's rebase feature is a *very* nice, clean way to keep a feature
> branch up to date with the master branch. But, as you've seen,
> rebasing can make things a bit confusing you need to push that feature
> branch to other people.
>
> I've found that a good rule of thumb is to never rewrite (i.e. rebase)
> branches that have already been shared with others. Of course there's
> nothing impossible or fundamentally bad about pushing rewritten
> branches like this. But, unless people are expecting it to happen and
> know how to deal with it when they pull, it can cause confusion,
> particularly on teams that are just getting acquainted with Git.
>
> Instead, if a feature branch is going to be shared with others, and
> it's going to be long-lived, then we keep it up-to-date by merging
> from master every now and again, rather than rebasing.
>
> On the other hand, if I'm working on a feature branch by myself, and I
> haven't shared it with anyone yet, I frequently rebase against master
> to keep things clean. I also use interactive rebase a lot to tidy up
> commits. But as soon as I've shared my branch with the team, I no
> longer do any rebasing/rewriting.
>
> If there are Git wizards on your team, it is true that they may find
> this an inflexible way of working. But I've found it to be a good
> compromise between ease of pulling and maintaining a clean commit
> history.
>
> Chris
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>
Bradley Wagner· Aug 13, 2010, 20:38 UTC · re: Chris Mear · lore

Re: workflow for working on feature branches and incrementally incorporating "master" changes

Thanks for the explanation Chris! That definitely helps.
Show 30 quoted lines
> > If you're working on a feature branch by yourself, what is a good
> > workflow for keeping the branch in up-to-date with "master" as you're
> > developing on the feature branch or is this unnecessary? Should you
> > just wait until you want to officially integrate the feature branch
> > into the "master"?
> >
> > We were doing:
> >
> > commit to local feature branch
> > push to remote feature branch
> > ... repeat....
> > rebase from master (occasionally)
> > push to remote
> >
> > but at this point the branches have diverged.
> >
> > We're coming at this from SVN, so we might just be thinking about this
> > the wrong way.
>
> Git's rebase feature is a *very* nice, clean way to keep a feature
> branch up to date with the master branch. But, as you've seen,
> rebasing can make things a bit confusing you need to push that feature
> branch to other people.
>
> I've found that a good rule of thumb is to never rewrite (i.e. rebase)
> branches that have already been shared with others. Of course there's
> nothing impossible or fundamentally bad about pushing rewritten
> branches like this. But, unless people are expecting it to happen and
> know how to deal with it when they pull, it can cause confusion,
> particularly on teams that are just getting acquainted with Git.
Two questions here.

First, the command to rebase based off another branch that is *not* the upstream branch involves --onto, correct? For example, if I've been working on branch awesome_feature and I want to rebase using all the work that's been done in master since my branch was created, would I use: "git rebase --onto master <upstream_repo_name>"

Secondly, as someone pulling a branch that has been rewritten, do I use the --force flag: "git pull --force" or will rebasing suffice?

Show 16 quoted lines
> Instead, if a feature branch is going to be shared with others, and
> it's going to be long-lived, then we keep it up-to-date by merging
> from master every now and again, rather than rebasing.
>
> On the other hand, if I'm working on a feature branch by myself, and I
> haven't shared it with anyone yet, I frequently rebase against master
> to keep things clean. I also use interactive rebase a lot to tidy up
> commits. But as soon as I've shared my branch with the team, I no
> longer do any rebasing/rewriting.
>
> If there are Git wizards on your team, it is true that they may find
> this an inflexible way of working. But I've found it to be a good
> compromise between ease of pulling and maintaining a clean commit
> history.
>
> Chris
Jon Seymour· Aug 10, 2010, 22:32 UTC · re: Bradley Wagner · lore

Re: workflow for working on feature branches and incrementally incorporating "master" changes

I'll describe the workflow that works very well for me.

I use a single branch, working, as a working branch. I NEVER publish the tip of this branch. Rather, it always contains my working tree which consists of:

- a base, which is a merge of:
   - completed work I have yet to publish
   - the upstream branch, as pulled at some previous time
   - fixes from other people that have yet to be integrated into the upstream
- a linear series of one or more commits that I am currently working on
- the tip, or HEAD of the working branch.
Here are some typical workflows:
- pull from upstream:
   - fetch the upstream (git fetch upstream)
   - checkout the branch tracking the BASE of my working branch (git
checkout working-base)
   - merge with the upstream (git merge upstream/master)
   - rebase the linear bit of my work on that (git rebase working-base working)
- isolate some work as a fix to some upstream build tag (BUILD-XXXX)
  - fetch tags from upstream (git fetch upstream refs/tags/*:refs/tags/*)
  - create a new branch for the topic (git branch topic HEAD)
  - create a new base branch for the topic (git branch topic-base HEAD~N)
  - rebase the topic onto the BUILD-XXX tag (git rebase --onto
BUILD-XXX topic-base topic && git branch -f topic-base BUILD-XXX)
  - merge the topic into the base of my working branch (git checkout
working-base && git merge topic)
  - rebase the remainder of the working branch onto the updated
working-base (git rebase working-base working)
- patch a previously isolated topic with the top commit from the working branch
  - create a temporary branch for the fix ( git branch -f topic-fix
HEAD && git rebase --onto topic HEAD~1 topic-fix)
  - update the topic ( git checkout topic && git merge --ff-only
topic-fix && git branch -d topic-fix)
  - merge the topic back into the base of my working tree ( git
checkout working-base && git merge topic && git rebase working-base
working)
- publish a topic
  - git tag topic-XXX topic && git branch -f topic-base topic-XXX &&
git push public topic-XXXX
- integrate a tag someone else has published into my base
  - git checkout working-base && git merge other-topic-XXX && git
rebase working-base working
This way of working has some very nice properties:
* the base of my working branch (working-base) contains all my
_dependencies_, that is:
   * the upstream branch
   * my finished, but un-integrated work
   * other people's finished but un-integrated work
* integrating dependencies is done the same way, irrespective of where
they come from, e.g.:
   git checkout working-base && git merge dependency && git rebase
working-base working
* the base of my branch is a  merge hell, but I don't care, because it
is built from well known, relatively stable dependencies - I can throw
it away and rebuild it any time relatively easily.
* my working tree remains stable - it always contains stuff I have
recently worked on, or stuff I want
* my topic branches remain clean and uncluttered with merges, so I can
release them to others without dragging unwanted stuff along
* merges tend to be trivial, since they are based on stable work.
rebases are usually easy, because they are used only used on a
relatvely small amount on unpublished, unstable work

This only downside to the workflow is the complexity of using an extra branch (working-base) to track the base of the working branch. If you forget to update it, you can accidentally do some stupid things (which can be fixed by using the info in git reflog).

In fact, this workflow is so useful to me, that I believe it needs its own git porcelain to assist with the management. I am, in fact, developing two commands to do just this: git base and git work.

git base manages the base of the branch (using a reference called refs/bases/<branch>) while git work helps to manage the workflow of maintaining the base of the branch. With these two (as yet unpublished commands), the workflows above become as simple as:

 * initialise the base: git base set upstream/master
 * sync with upsteam: git work merge upstream/master
 * merge with some dependency: git work merge dependency-XXXX
 * create a new topic from recent work: git work create topic HEAD~N BUILD-XXX
 * update an existing topic with recent work: git work update topic HEAD~N
 * rebase onto a clean base: git work rebase BUILD-XXX
 * visualize just the current work: gitk $(git work)  (which expands
as gitk $(git base)..working or gitk refs/bases/working..working)
 etc.

I hope to have time to release some feature stable contributions in a week or two...stay tuned.

Regards,
jon.

On Wed, Aug 11, 2010 at 6:20 AM, Bradley Wagner <bradley.wagner@hannonhill.com> wrote:

Show 25 quoted lines
> If you're working on a feature branch by yourself, what is a good
> workflow for keeping the branch in up-to-date with "master" as you're
> developing on the feature branch or is this unnecessary? Should you
> just wait until you want to officially integrate the feature branch
> into the "master"?
>
> We were doing:
>
> commit to local feature branch
> push to remote feature branch
> ... repeat....
> rebase from master (occasionally)
> push to remote
>
> but at this point the branches have diverged.
>
> We're coming at this from SVN, so we might just be thinking about this
> the wrong way.
>
> Thanks!
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

← back to recent threads