Skip to content

Custom Workflows

Valentino Stoll edited this page Nov 8, 2018 · 2 revisions

Git-reflow's default process isn't meant to fit every team, which is why we've introduced Workflows.

As of git-reflow versions >= 0.9.0, you can use a special file that can contain customizations to the default process. With this, you can:

  1. Add hooks to be run before, or after any command
  2. Use one of our pre-configured workflows as a basis for your own
  3. Override any of the default commands
  4. Create new commands


# Use a pre-defined workflow
use "FlatMergeWorkflow"

# Do something before the `start` command
before :start do
  say "Booya! Started this bad girl."

# Do something after the `deliver` command
after :deliver do
  run "say 'Well done!'"

# Override the `start` command to auto-name feature branches
command :start, arguments: { feature_branch: nil }, flags: { base: 'dev' }, switches: { loud: false } do |**params|
  base_branch    = params[:base]
  feature_branch = params[:feature_branch] || "feature-#{"%Y-%m-%d")}"

  run_command_with_label "git checkout #{base_branch}"
  run_command_with_label "git pull origin #{base_branch}"
  run_command_with_label "git push origin #{base_branch}:refs/heads/#{feature_branch}"
  run_command_with_label "git checkout --track -b #{feature_branch} origin/#{feature_branch}"

# Create a new command
command :boom do
  GitReflow.say "Boom."

The block that you pass to each of the git-reflow reserved commands (use, before, after, command) are executed in the context of our Core workflow class. This gives you the ability to use any code available to GitReflow. We encourage you to use as much of GitReflow's tooling as possible so that you can take full advantage of getting the current branch name, logging, exception-handling, colorized output, and several other features that are baked into GitReflow's internals. For a full list of what's available, see the Available Workflow Helpers section.

Available Workflow Helpers

Command-line helpers:

  • run, or GitReflow.run_command_with_label – Easily run commands
  • say – output something to the STDOUT with special formatting Git-related helpers:
  • git_root_dir – The root directory of your git repository
  • remote_user – The username the repository belongs to (e.g. reenhanced for this repo)
  • remote_repo_name – The name of the repository (e.g. gitreflow for this repo)
  • current_branch – The currently checked out branch
  • update_current_branch – Pulls in the latest changes from remote for the current branch
  • push_current_branch – Pushes the current branch to remote
  • fetch_destination(branch_name) – Fetches branch_name from remote
  • update_destination(branch_name) – Checks out branch_name, pulls in latest changes from remote, then re-checks-out the branch you were on
  • update_feature_branch – Pulls in any changes from remote for the current branch, then merges in any changes from remote/base_branch
  • append_to_squashed_commit_message(message) – Append message to the squashed commit message

Also of note, GitReflow.git_server.connection will give you access to the api for your git server. In the case of GitHub, it is the equivalent of

You can’t perform that action at this time.