#!/usr/bin/env ruby ############################## # Create local tracking branches for all remote branches # that don't have local branches with a matching name. # # TODO: Add remote name as an agument # TODO: Add option for pass-through grep arguments to filter branches ############################## # TODO: Accept this as an argument REMOTE = 'origin' # Filter only branches not already existing locally local_branches = %x(git branch | sed 's/^*/ /' | sort).split remote_branches = %x(git branch -r | sed 's&#{REMOTE}/&&' | sort).split untracked_branches = remote_branches - local_branches # Create a tracking branch for each untracked branch untracked_branches.each { |branch| remote_branch = "#{REMOTE}/#{branch}" puts "Creating a tracking branch for #{branch}:#{remote_branch}" %x(git branch --track #{branch} #{remote_branch}) }