Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
executable file 35 lines (26 sloc) 998 Bytes
#!/usr/bin/env ruby
$ git sync <newbase> [branch]
"git sync master topic" is shorthand for the following:
$ git rebase master topic
$ git checkout master
$ git merge --ff-only topic
$ git checkout <previous branch>
Note that the ordering of the arguments here is the same as for rebase. In general, use "git sync master" from
your topic branch.
abort USAGE unless (["-h", "--help"] & ARGV).empty?
abort USAGE if ARGV.empty?
new_base = ARGV[0]
branch_output = `git branch --no-color`.split("\n").select { |name| name =~ /^\*/ }
abort "Not on a valid branch" unless branch_output.size == 1
current_branch = branch_output[0].gsub(/^\*\s+/, "")
target_branch = ARGV.size > 1 ? ARGV[1] : current_branch
def run_and_check(command)
abort unless system command
run_and_check "git rebase #{new_base} #{target_branch}"
run_and_check "git checkout #{new_base}"
run_and_check "git merge --ff-only #{target_branch}"
run_and_check "git checkout #{current_branch}"