Skip to content

Instantly share code, notes, and snippets.

@AlexeyMK
Last active April 27, 2020 06:06
Show Gist options
  • Save AlexeyMK/aef5403766082970d089562549061749 to your computer and use it in GitHub Desktop.
Save AlexeyMK/aef5403766082970d089562549061749 to your computer and use it in GitHub Desktop.
Useful Git snippets from my time at Opendoor
# stick these in ~/.gitconfig
[alias]
bl = "!~/.bin/bl.sh"
# ensure you are on latest master before creating a PR
prep = "!git checkout master && git pull --rebase && git checkout - && git rebase master"
# commit, get the commit message, and then immediately start writing up the PR.
cmpr = "!git add . && git commit -a $1 && git push && open https://github.com/opendoor-labs/$(basename `pwd`)/compare/master...$(git rev-parse --abbrev-ref HEAD)"
# got feedback? make the changes, then append it to the last commit and push it up.
apl = "!git add . && git commit --amend --no-edit && git push --force-with-lease --set-upstream"
# random other nice shortcuts.
git = "!git ${@:2}" # fix 'git git' scenario
ca = commit --amend
co = checkout
nb = checkout -b
rc = rebase --continue
pr = pull --rebase
[color]
branch = auto
diff = auto
interactive = auto
status = auto
[push]
default = current
[help]
autocorrect = 1
[credential]
helper = osxkeychain
#!/usr/bin/env ruby
# written by @codeferret
require 'io/console'
begin
require 'colorize'
rescue LoadError
puts 'Running without colors. Install colorize gem for colors'
end
branches = `git branch --sort=-committerdate | head -n 10`.lines
COLORS = [
:light_red,
:yellow,
:green,
:cyan,
:magenta,
].freeze
max_length = branches.map(&:length).max
branches.each_with_index do |branch, idx|
color = COLORS[idx % COLORS.count]
puts "#{idx}: #{branch.strip.ljust(max_length)} #{idx}".colorize(color).bold
end
choice = STDIN.getch
if choice !~ /[0-9]/
exit 0
end
system("git co #{branches[choice.to_i]}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment