Created
December 8, 2015 19:06
-
-
Save slucero/32e8c98478d87b555fe4 to your computer and use it in GitHub Desktop.
Git command script to locally track all remote branches
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment