Open tonilopezmr opened 6 years ago
This changed a lot since I'm using Graphite, It'll update the branches automatically, with a single command.
You can learn more in the Getting Started docs.
$ gt user branch-prefix --set kevin/
$ gt user editor --set vim
$ gt auth --token <PASTE>
# Optional (use original commit date/author on internal rebase/restack)
$ gt user restack-date --use-author-date
$ gt bco main
# do work
$ git add .
$ gt bc wip/foo-bar-baz
# do more work
$ git add .
$ gt cc -m "something"
# branch is probably ready to submit but I have related work to do
$ gt b rename kevin/foo-bar-baz
# do related work
$ git add .
$ gt bc wip/new-stack
# more work
$ git add .
$ gt ca
$ gt b rename kevin/new-stack
# ready to submit the whole stack
$ gt ss
Itβs not uncommon for me to have multiple unrelated wip
branches. For example my current seaplane
repo looks like this:
$ gt l
β― kevin.asyncify PR #118 (Draft)
β [DO NOT MERGE] Convert to async
β 4 days ago
β * a4fc67 - update doc examples to async
β * 47dd62 - update api tests to async
β * 12cb09 - makes the SDK async
β
β β― wip.formation-configuration-command
β β 4 days ago
β β * 419062 - stub formation configuration commands
β β
β β β wip.init-ui-tests (current)
β β β 4 days ago
β β β * 40cb81 - init-ui-test: adds base init tests
β β β
ββββ΄βββ
β
β― main
β 4 days ago
β
gt bco foo
(b
ranch c
hecko
ut): Check out existing branch foo
gt b top
(b
ranch): Go to the top of the stack (or gt b up
to go up one level)gt b bottom
: Go to the bottom of the stack (gt b down
to go down one level)gt b rename
: Rename current branchgt bco foo && gt sr
: Check out foo
which is behind main
and catch it up on top of main
gt sr
(s
tack r
e-stack): Regenerate graphite metadata based on current git
structure (i.e. you did some git
commands to mess with branches an now want Graphite to re-track it all)gt ss
(s
tack s
ubmit): Submit or update the stackgt ss -u
(update-only): Submit the stack, but only update existing PRsgt cc -m "foo"
(c
ommit c
reate): Create a commit with message βfooβgt ca
(c
ommit a
mend): Amend last commitgt l
(l
og): Display the branch stack graphgt rs
(r
epo s
ync): Repo sync; pull down latest changes and branches, rebasing as requiredMore specialized command are the gt ds
and gt us
(d
owns
tack/towards main
and u
ps
tack/away from main
) which I primarily use with sync
so... gt dss [-u]
or gt uss [-u]
.
So your PR was approved πΒ Now youβre ready to merge. But wait!
The best method to merge stacked PRs is either bottom to top (closest to main
to furthest way from main
). One could also use a top to bottom (furthest away from main
down to main
) approach, but you lose some benefits in stacked PRs (i.e. the end result in main
is a single squashed PR from all stacks).
β οΈΒ Do not merge a stacked PR without the base branch (the PR immediately below it, or closer to main
) having been approved first! β οΈ
Imagine a stack of Three PRs which Graphite displays at the command line roughly this:
$ gt l
β kevin.branch-3 (current) PR #3
β 4 days ago
β * a4fcef - even more work
β
β― kevin.branch-2 PR #2
β 4 days ago
β * b2fc11 - some more work
β
β― kevin.branch-1 PR #1
β 4 days ago
β * c5fc67 - some work
β
β― main
β 4 days ago
Or in the PR comment displayed like:
β main
β― PR branch-1 #1 Graphite (this PR)
β― PR branch-2 #2 Graphite
β― PR branch-3 #3 Graphite
PR 1
to be approved and merge into main
(do this β
)PR 2
to be approved and merge into main
PR 3
to be approved and merge into main
Sometimes after you merge a base branch, the branch/PR above it contains merge conflicts as reported by Github. In these situations my workflow generally looks like this:
$ gt rs
# Pull down the latest, including the recent merge
# pick 'y' to delete old merged branches
$ gt l
# Make sure Graphite automatically rebased in-flight PRs to stay
# above 'main'
# You can see this by if your open PRs are above or below 'main'
# if they have fallen below 'main' and Graphite didn't automatically
# fix them up
$ gt bco my-next-pr-branch
# check out the PR branch that is next up
$ gt sr
# rebase onto main
# do any normal rebase fixing required, potentially with rounds
# of 'gt continue' (git rebase --continue)
$ gt ss [-u]
# Ensure the in-flight PRs are updated appropriately
#
# Add -u if you have branches in the stack that do not have active PRs
07/03/2018
The current branches are:
When you want to merge with squash like this
B - squash -> A - squash -> master
you need to follow this steps:A to master
A
git rebase --onto master <last commit message from A> B
in the B branchgit push -f
, the changes will apply then you can merge directlyB to master
πUpdate - 05/06/2018
Now, you can use @Serchinastico amazing gist to do the steps above automatically with a script in
.gitignore
.https://gist.github.com/Serchinastico/98cea9fcc2733689e63c57191257bd2c