Custom Git Workflows with the latest git-reflow
Tags: git, gitreflow, workflows, ruby
Published: 2019-08-23 19:12:05

---
title: Custom Git Workflows with the latest git-reflow
published: true
tags: git,git-reflow,workflows,ruby
canonical_url: https://blog.codenamev.com/git-reflow-workflows/
---

![New git-reflow release: Custom Git Workflows](https://blog.codenamev.com/content/images/2019/07/reflow-workflows-header.jpeg)

This release includes the culmination of several years of effort to allow you to customize our process to suit your specific needs. We’ve dropped a heavy dependency (`gli`) and introduced a pretty slick DSL for creating new git commands or override our existing ones.

I am really excited to announce the released version 0.9.0 of the [`git_reflow` gem](https://github.com/reenhanced/gitreflow)!

### Custom Workflows

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

We’ve introduced 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

Here is an example showcasing all the various ways you can customize the process:

```ruby
# Use a pre-defined workflow
use "FlatMergeWorkflow"

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

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

# 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-#{Time.now.strftime("%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}"
end

# Create a new command
# Makes `git reflow boom` available in the command line.
command :boom do
  GitReflow.say "Boom."
end
```

You can define a unique workflow for each of your projects simply by placing it in the root of your project, or by setting a special `reflow.workflow` git-config setting with the full path of the file.


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](https://github.com/reenhanced/gitreflow/blob/master/lib/git_reflow/workflows/core.rb). This gives you the ability to use any code available to the `GitReflow` module. 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 [Available Workflow Helpers](https://github.com/reenhanced/gitreflow/wiki/Custom-Workflows#available-workflow-helpers) on our wiki.

### Ramping Up To 1.0

With the re-workings of `Workflows` in place, we’re getting ready for our first major release! Our current plans are to focus on:

1. Introduce Pivotal Tracker & Trello workflows
2. Add GitLab integration
3. Add an Open Source workflow

We’re looking forward to some exciting times! We’d love to hear all the interesting ways you use these new workflows, so please don’t hesitate to let us know.

Happy hacking!