Skip to content

Instantly share code, notes, and snippets.

@trak3r
Forked from anonymous/git-merge-into
Created May 16, 2011 15:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trak3r/974657 to your computer and use it in GitHub Desktop.
Save trak3r/974657 to your computer and use it in GitHub Desktop.
Merge the current branch into another branch without (manually) switching
#!/usr/bin/env ruby
# Merges the current branch into the specified branch after checking out that branch.
# Usage:
# git merge-into [branch]
# [branch] defaults to "master" if not specified
# "sprint" is my convenience library for handling external processes.
# You can get it at http://github.com/softcraft-development/sprint and/or http://gemcutter.org/gems/sprint
# You can also replace it with a combination of back-ticks (``) and $? if you prefer.
require 'rubygems'
require 'sprint'
#grab the current branch name
branches = sprint "git branch --no-color"
match = /^ *\* *(.+)/.match(branches.to_s)
current_branch = match ? match[1] : nil
#target branch is the first argument to git-merge-into
target_branch = ARGV[0] || "master"
if current_branch
switch = sprint "git checkout #{target_branch}"
if switch.success?
merge = sprint "git merge #{current_branch}"
if merge.success?
puts "Merged #{current_branch} into #{target_branch}"
end
end
sprint "git checkout #{current_branch}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment