Skip to content

Instantly share code, notes, and snippets.

@ben
Last active December 11, 2015 13:39
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ben/f17410d1b72b40e96e9d to your computer and use it in GitHub Desktop.
Save ben/f17410d1b72b40e96e9d to your computer and use it in GitHub Desktop.
Resources from git/GitHub tips & tricks talk at PHP Benelux
export CLICOLOR=1
. ~/.git-completion.bash
# @gf3’s Sexy Bash Prompt, inspired by “Extravagant Zsh Prompt”
# Shamelessly copied from https://github.com/gf3/dotfiles
# Screenshot: http://i.imgur.com/s0Blh.png
if [[ $COLORTERM = gnome-* && $TERM = xterm ]] && infocmp gnome-256color >/dev/null 2>&1; then
export TERM=gnome-256color
elif infocmp xterm-256color >/dev/null 2>&1; then
export TERM=xterm-256color
fi
if tput setaf 1 &> /dev/null; then
tput sgr0
if [[ $(tput colors) -ge 256 ]] 2>/dev/null; then
MAGENTA=$(tput setaf 9)
ORANGE=$(tput setaf 172)
GREEN=$(tput setaf 190)
PURPLE=$(tput setaf 141)
WHITE=$(tput setaf 256)
else
MAGENTA=$(tput setaf 5)
ORANGE=$(tput setaf 4)
GREEN=$(tput setaf 2)
PURPLE=$(tput setaf 1)
WHITE=$(tput setaf 7)
fi
BOLD=$(tput bold)
RESET=$(tput sgr0)
else
MAGENTA="\033[1;31m"
ORANGE="\033[1;33m"
GREEN="\033[1;32m"
PURPLE="\033[1;35m"
WHITE="\033[1;37m"
BOLD=""
RESET="\033[m"
fi
export MAGENTA
export ORANGE
export GREEN
export PURPLE
export WHITE
export BOLD
export RESET
function parse_git_dirty() {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "⚡"
}
function parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/"
}
PS1="\033[G\[${BOLD}${MAGENTA}\]\u \[$WHITE\]in \[$GREEN\]\w\[$WHITE\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on \")\[$PURPLE\]\$(parse_git_branch)\[$WHITE\]\n\$ \[$RESET\]"
[user]
name = Me
email = bs@github.com
[color]
ui = true
[alias]
lg = log --graph --all --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative

Intro

Git

Rebase

  • Several ways to get branches in sync
  • git merge master -> merge commit
  • gitx
  • Roll it back
  • git reflog
  • git reset --hard HEAD@{1}
  • gitx
  • git rebase master
  • gitx
  • git rebase master --interactive
  • jdjcws:wq
  • keep only last message
  • gitx

Bisect

  • Has this ever happened to you? I just found a bug, and it's bad
  • ./new_test.sh
  • git lg
  • git bisect start
  • git bisect good 2b241
  • git bisect bad
  • git lg -> where are we?
  • ./new_test.sh
  • git bisect good
  • git lg -> more refs added
  • test/bisect until found
  • git show -> oh, okay, I know how to fix that
  • git lg
  • git bisect reset
  • git lg
  • But what if there really was 10 years of history? What if the test took 2 hours to run?
  • git bisect good 2b241 / enter
  • git bisect bad
  • git bisect run ./new_test.sh -> go home for the weekend
  • git bisect reset

Submodule

  • As a project matures, you find that parts can be broken out
  • git submodule add ../bisect; git commit -m 'Add submodule'
  • git show
  • cd bisect
  • git lg
  • Wait, didn't this project have a security issue?
  • git checkout bf4a9
  • cd ..
  • git diff
  • git commit -am 'Avoid security issue'
  • Caveat: submodules can be tricky because of git's default behavior
  • tree
  • git clone . sm; cd sm; tree -> bisect is empty!
  • git submodule update --init; tree

Filter-Branch

  • Rewrite all the things
  • git lg
  • take credit for someone else's work
  • git filter-branch --env-filter 'GIT_AUTHOR_NAME=Me' HEAD~10..HEAD
  • git lg
  • Remove sensitive information
  • ls
  • git filter-branch -f --tree-filter 'rm -f pom.xml' -- --all
  • ls
  • Convert a package into a separate repo
  • git filter-branch -f --subdirectory-filter src --prune-empty -- --all
  • ls

Shell

  • May have noticed my prompt
  • vi ~/.bash_profile
  • CLICOLOR -> color for basic commands by default
  • git-completion: tab completion for named things
  • G
  • Zap when dirty
  • :q
  • touch hi
  • vi ~/.gitconfig
  • color.ui=true
  • lg alias

GitHub

Pull Requests

  • help article
  • rails/rails #9011
  • Epic pull requests
  • delorean += flux capacitor

Emoji

Subversion

Hub

  • alias git=hub
  • git browse twitter/iago
  • git clone twitter/iago
  • cd iago
  • git browse

GHfW

  • GH account/repos
  • History view
  • Open Shell Here
  • touch hi
  • Zoom in on shell prompt

GHfM

cowsay Rebase!
git lg
gitx
git merge master
git reflog
git reflog my_feature
git reset --hard my_feature@{1}
git rebase master
git rebase master --interactive
cowsay Bisect!
./new_test.sh
ls
git lg
git bisect start
git bisect good 2b241
git bisect bad
git lg
./new_test.sh
git bisect good
git lg
./new_test.sh
git bisect bad
./new_test.sh
git bisect bad
git show
git lg
git bisect reset
git lg
git bisect good 2b241
git bisect good
git bisect bad
git bisect reset
git bisect good 2b241
git bisect bad
git bisect run ./new_test.sh
cowsay Submodules!
git bisect reset
ls
ls -la
git lg
git submodule add ../bisect
git commit -am 'submodule'
git show
cd bisect/
git lg
git checkout bf4a9
cd ..
git status
git diff
git commit -am 'Avoid security issue'
git clone . sm
cd sm
ls
cd ..
rm -rf sm
tree
git clone . sm
cd sm
tree
git submodule update --init
tree
cowsay Filter-Branch!
git lg
git filter-branch --env-filter 'GIT_AUTHOR_NAME=Me' HEAD~10..HEAD
git lg
ls
git filter-branch -f --tree-filter 'rm -f pom.xml' -- --all
ls
git checkout 1.1.x
ls
git checkout master
ls
git filter-branch -f --subdirectory-filter src --prune-empty -- --all
ls
cowsay Shell Tricks!
git log
vi ~/.bash_profile
git log
git lg
cowsay Subversion!
svn co https://github.com/retlehs/roots
tree -AL 2 roots
cowsay Hub!
hub --version
alias git=hub
git browse twitter/iago
git clone twitter/iago
git clone twitter/iago
cd iago/
ls
ls -la
hub --help
./scripts/historytailbash 1 100
vi ~/.gitconfig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment