Skip to content

Instantly share code, notes, and snippets.

@Boztown
Last active September 15, 2016 18:08
Show Gist options
  • Save Boztown/e56a02a4df68d69a396b1127481ce67b to your computer and use it in GitHub Desktop.
Save Boztown/e56a02a4df68d69a396b1127481ce67b to your computer and use it in GitHub Desktop.
Post-Checkout GIT hook to change database_yml to the name of my current branch.
#!/usr/bin/env ruby
gem 'psych'
require 'psych'
branch = `git branch | grep '*' | cut -c 3-`.chomp
branch.gsub! '/', '_'
branch.gsub! '-', '_'
f = Psych.load_file("config/database.yml")
f["development"]["database"] = "ms_" + branch.to_s
File.open('config/database.yml', 'w') do |file|
file.write(Psych.dump(f).gsub("---\n", ''))
end
puts "Local development has been switched to: " + branch
@Boztown
Copy link
Author

Boztown commented Sep 15, 2016

Chuck this bad boy in .git/hooks/post-checkout, crack a beer and enjoy.

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