Skip to content

Instantly share code, notes, and snippets.

@jperkin
Created October 1, 2012 15:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jperkin/3812675 to your computer and use it in GitHub Desktop.
Save jperkin/3812675 to your computer and use it in GitHub Desktop.
git branching plan
--A-------B-------C--D------------E------F--- origin/trunk
/ / / /
--------------------------------------------- upstream/trunk
\ \
-- upstream/pkgsrc_2012Q2 -- upstream/pkgsrc_2012Q3
- upstream/trunk is clean pkgsrc HEAD
- origin/trunk tracks upstream/trunk periodically, and adds Joyent-specific changes
- pkgsrc gets branched every quarter
We want to:
- Create quarterly release branches
- Apply changes A-E, preserving history
- Make it easy to cherry-pick F..
@apbarrett
Copy link

Suppose you want a new branch called "newbranch" which is based on upstream/pkgsrc_2012q3, but also has changes A to E.

I'd probably stare by creating the new branch from commit E,
then rebase the new branch onto upstream/pkgsrc_2012Q3.

Commit E is 2 commits before the head of origin/trunk,
so if you don't have a tag there, you can add one:

$ git tag base-for-newbranch origin/trunk~2

Use gitk to check that the tag is in the right place.

Then checkout that tag and create the branch:

$ git checkout base-for-newbranch
$ git branch newbranch

Now the tree looks like this:

                                      --------- newbranch
                     /
  --A-------B-------C--D------------E------F--- origin/trunk
 /     /         /          /          /
--------------------------------------------- upstream/trunk
    \                          \
     -- upstream/pkgsrc_2012Q2  -- upstream/pkgsrc_2012Q3

Now rebase newbranch ontp upstream/pkgsrc_2012Q3:

$ git rebase --onto upstream/pkgsrc_2012Q3 upstream/trunk newbranch

That means: take the changes that are in newbranch and are not in
upstream/trunk, and apply those changes to upstream/pkgsrc_2012Q3,
and call the result "newbranch".

So now you should have this:

  --A-------B-------C--D------------E------F--- origin/trunk
 /     /         /          /          /
--------------------------------------------- upstream/trunk
    \                          \
     -- upstream/pkgsrc_2012Q2  -- upstream/pkgsrc_2012Q3
                    \
                                     --A'--B'--C'--D'--E'-- newbranch

where A' to E' contian essentially the same changes as A to E.

@apbarrett
Copy link

I can't figure out how to edit comments, but there are some slashes and backslashes with the wrong amount of space before them, and some spelling mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment