Skip to content

Instantly share code, notes, and snippets.

@zanloy

zanloy/setup_git.rb

Created Sep 22, 2014
Embed
What would you like to do?
Setup git aliases
#!/usr/bin/env ruby
require 'optparse'
options = { :realm => :local }
OptionParser.new do |opts|
opts.on('-g', '--global', 'Set aliases globally') do
options[:realm] = :global
end
opts.on('-l', '--local', 'Set aliase locally') do
options[:realm] = :local
end
end.parse!
case options[:realm]
when :global
cmd = 'git config --global'
when :local
cmd = 'git config'
else
raise "You must specify whether these changes should be --global or --local."
end
aliases = {
co: 'checkout',
ci: 'commit',
st: 'status',
br: 'branch',
hist: 'log --pretty=format:"%h %ad | %s%d [%an]" --graph --date=short',
rb: 'rebase',
unpushed: '!GIT_CURRENT_BRANCH=$(git name-rev --name-only HEAD) && git log origin/$GIT_CURRENT_BRANCH..$GIT_CURRENT_BRANCH --oneline',
undo: 'reset --soft HEAD^',
up: '!git fetch --all -tp; git merge --ff-only @{u}; git submodule update --init --recursive',
cp: 'cherry-pick',
}
aliases.each do |a,c|
`#{cmd} alias.#{a} '#{c}'`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.