A cli that provides a set of git wf
subcommands which simplify dealing with
feature branches & GitHub pull requests. Does not require a GH API token, as
it just opens your browser to complete Pull Request operations.
- creates named feature branches which track their intended "parent" (
start
) - opens pull requests against the intended parent branch (
pr
) - cleans up when done (
done
) - aborts abandoned branches cleanly (
abort
) - renames branches locally & on server (
rename
) - additional optional release management commands (
cut-release
,qa
,hotfix
,merge-back
)
Below we use the term main
to refer to your mainline branch; if you have a
main
branch in your local checkout, we'll assume that's the one you're using.
If not, we'll assume you're using master
.
$ npm install -g git-wf
If your GitHub username does not match $USER
in your environment, you
should set the $GH_USER
env var to your GitHub username wherever you
set your shell's environment variables.
$ git wf --help
The start
, pr
, abort
, rename
, and done
commands can be used on any
project that has a master or main branch.
All of the other commands will enforce the existence and use of the main
,
release
, and hotfix
branch naming scheme.
Given you are currently on branch <parent>
- Updates the branch you currently have checked out with
git pull
- Creates a new feature branch named
<name>
locally withgit checkout -b <name>
- If you specified
--fork
or already have a remote namedfork
:- verifies you have a remote named
fork
- if you don't, verifies that
<yourusername>/<reponame>
exists on github, and if not prompts you to create it - if you do have a github fork, creates the
fork
remote for you - Pushes your feature branch to
fork
as a branch namedfeature/<parent>/<name>
withgit push -u fork <name>:feature/<parent><name>
- verifies you have a remote named
- If you didn't, pushes your feature branch to
origin
as a branch named<yourusername>/feature/<parent>/<name>
withgit push -u origin <name>:<yourusername>/feature/<parent>/<name>
If you decide you don't like your name, from a checked out feature branch run this command, passing a new name, it will:
- Fetch the latest commits from the remote
- Create a new remote branch named correctly, based on the fetched version of the old remote branch (no new commits from local)
- Create a new local branch with the new name, based on the current local branch
- Make the former the upstream of the latter
- Delete the old local branch
- Delete the old remote branch
If you decide you don't like your new feature, you may PERMANENTLY delete it,
locally and remotely, using git wf abort
. This will:
- Commit any working tree changes as a commit with message "WIP"
- Save the SHA of whatever the final commit was
- Switch to the parent branch
- Delete the local branch, remote branch, and remote tracking branch.
- Output the final SHA in case you change your mind.
Given you are currently on a feature branch named <name>
, makes sure all your
work is pushed to origin
or fork
, then opens your browser to a GitHub PR
creation page to merge that back to its parent branch.
Given you are currently on a feature branch named <name>
- Switches to inferred parent branch with
git checkout <parent>
- Updates the parent branch with
git pull --no-rebase
- Deletes the feature branch with
git branch -d <name>
- Cleans up the corresponding remote branch with
git remote prune origin
- Runs
git wf merge-back
(see below) - Opens a PR, as per
git wf pr
to mergebranch
(default:main
) torelease
- If no
[branch]
is given, defaults to current branch - If
[branch]
isrelease
, runsgit wf merge-back
- Switches to
[branch]
withgit checkout [branch]
- Updates with
git pull --no-rebase
- Tags
HEAD
of[branch]
asbuild-YYYY.mm.dd_HH.MM.SS
withgit tag build-...
- Pushes tag with
git push origin tag build-...
- Switches to
hotfix
branch - Pulls latest updates
- Fast-forward merges
hotfix
to given build tag - Pushes
hotfix
branch
- Switches to
hotfix
branch - Pulls latest updates
- Merges
hotfix
branch torelease
branch - if there are conflicts, it creates a feature branch for you to clean up the results, and submit a PR. If not, pushes the merged branch. - As before, but this time merging
release
ontomain
Here's a narrative sequence of events in the life of a project:
- The project starts with branches
main
,release
, andhotfix
all pointing at the same place - On branch main, you
git wf start widget-fix
- Now on branch
widget-fix
, you make some commits, decide it's ready to PR, and rungit wf pr
- The PR is tested, accepted, and merged, and at some point, while on branch
widget-fix
, you rungit wf done
, which cleans it up - You start a new features,
git wf start bad-ideea
, make a few commits, then realize you named it wrong, so yougit wf rename bad-idea
- which is fine until you realize you don't want it at all, so yougit wf abort
and it's all gone. - A few more good features go in, and it's time to
git wf cut-release
- now yourrelease
branch is pointing up-to-date withmain
, and people can resume adding features tomain
- It's time to QA your upcoming release, so you
git wf qa release
which creates abuild-...
tag - Your shiny new
build-...
tag is available for deploying however you do that, so you deploy it, QA it, and eventually release it to production. - Everything's progressing along, there's new stuff on
main
, maybe a new release has even been cut torelease
, when you realize there's a problem on production, so you rungit wf hotfix build-...
with the build tag that's currently on production. Yourhotfix
branch is now ready for fixes. - From the
hotfix
branch, yougit wf start urgent-thingy
and now you're on a feature branch off ofhotfix
- you make your commits to fix the bug andgit wf pr
- People review and approve your PR, it's merged to the
hotfix
branch, yougit wf done
to cleanup git wf qa hotfix
creates a newbuild-...
tag off of thehotfix
branch, which can be QAed, then (quickly!) deployed to production- Now's a good time to run
git wf merge-back
, which will take those commits sitting onhotfix
and merge them back onto therelease
branch you had in progress. This goes cleanly, so it just does it for you. - Then it goes to merge
release
back ontomain
, but uh-oh there are some conflicts by now, because someone fixed the problem a different way onmain
. No worries,git wf
will detect that, create a feature branch to resolve the conflicts, let you clean up the merge on that branch, and then yougit wf pr
and it will open a PR to review the resolution.
At every stage, you don't need to stop your forward progress, forget which your next planned release was, or anything else as you add new features and hotfix production issues.