Handy recipes for git'n it done.
Get tab-completion for all your git commands, including branch names!
-
Install homebrew, if you haven't already.
-
Install git and bash-completion via homebrew (you must install git via homebrew for this to work)
brew install git
brew install bash-completion
-
Add bash-completion to your
~/.bash_profile
in accordance with the message printed during installation, which probably looks like this:if [ -f `brew --prefix`/etc/bash_completion ]; then . `brew --prefix`/etc/bash_completion fi
- Download the git-completion.bash file here. This is usually stored in the home directory: ~/git-completion.bash
- In your ~/.bash_profile or ~/.bashrc or ~/.zshrc, add this line:
source ~/.git-completion.bash
- Make sure to restart terminal.
git for-each-ref --sort=-committerdate --format='%(committerdate:short) %(refname)' refs/heads
(also add refs/remotes to include remote branches)
Recommended that this is added to your ~/.bash_profile
function pr () {
local repo=`git remote -v | grep -m 1 "(push)" | sed -e "s/.*github.com[:/]\(.*\)\.git.*/\1/"`
local branch=`git name-rev --name-only HEAD`
echo "... creating pull request for branch \"$branch\" in \"$repo\""
git push -u origin $branch
open https://github.com/$repo/compare/$branch?expand=1
}
For use with your shell's alias
command, or you can copy and paste them into your ~/.bash_profile.
alias gs='git status'
alias gb='git branch'
alias gg='git log --graph --oneline —all'
alias go='git checkout'
alias gom='git checkout master'
alias gob='git checkout -b'
alias grim='git rebase --interactive master'
alias gri='git rebase -i'
alias gra='git rebase --abort'
alias grc='git rebase --continue'
alias gca='git commit --amend'
Includes only the files that changed and omits the boilerplate about the branch, etc. Alias as git s
, using git's built-in alias functionality.
git status -s
This command lists the most recent 100 commits one-per-line, in color, with a graph of the history on the left. Very handy for quickly looking at history or checking the relationships between branches. Alias it as git lg
. Change the -100
to any number of commits you'd like, or omit it entirely to see the whole history.
git log --oneline --decorate --graph --all -100
One of the most common frustrations with submodules is failing to update them or forgetting to init them. This command covers all those edge cases. It's easiest to get into the habit of running it after every pull on a repo that has submodules. Alias it as git subup
.
git submodule update --init --recursive
git log -n 1 --oneline | awk "{print \$1}" | tr -d \\n | pbcopy