Created
March 2, 2012 17:36
-
-
Save elasticdog/1959877 to your computer and use it in GitHub Desktop.
Git Workflow
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
[alias] | |
ap = add --patch | |
br = branch | |
ci = commit --verbose | |
co = checkout | |
df = diff | |
ds = diff --stat | |
empty-tree-sha1 = hash-object -t tree /dev/null | |
gone = git log --diff-filter=D --summary | |
lc = log ORIG_HEAD.. --stat --no-merges | |
lo = log --all --date-order --oneline --graph --decorate -M -C | |
low = log --all --date-order --pretty=format:'%C(yellow)%h%C(green)%d%C(reset) %s %C(cyan)[%cr] %C(magenta)<%an>%C(reset)' --graph --date=relative -M -C | |
patch = format-patch --patience --full-index -M -C | |
rb = rebase | |
rbi = rebase --interactive --autosquash | |
serve = !git daemon --reuseaddr --verbose --base-path=. --export-all ./.git | |
st = status --short --branch | |
staged = diff --cached | |
whitespace = !git diff --check $(git empty-tree-sha1) | |
who = shortlog --summary --email -- | |
whois = "!sh -c 'git log -i -1 --pretty=\"format:%an <%ae>\n\" --author=\"$1\"' -" |
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
### git aliases | |
alias g='git' | |
# change into git repo's top-level directory | |
alias gcd='cd $(git rev-parse --show-toplevel)' | |
alias gmup='master_update' | |
alias gmpu='master_push' | |
alias gsyn='sync_repo' | |
alias gbcr='branch_create' | |
alias gbup='branch_update' | |
alias gbmg='branch_merge' | |
alias gbbm='big_branch_merge' | |
alias gblg='branch_log' | |
alias gbdf='branch_diff' | |
### git functions | |
git_environment_vars() { | |
CURRENT_BRANCH="$(git symbolic-ref -q HEAD)" | |
CURRENT_BRANCH="${CURRENT_BRANCH#refs/heads/}" | |
TOPLEVEL_DIR="$(git rev-parse --show-toplevel)" | |
WORKING_DIR="$PWD" | |
} | |
master_update() { | |
if git config --get 'branch.master.remote'; then | |
git_environment_vars | |
cd "$TOPLEVEL_DIR" | |
git checkout master | |
git pull --rebase | |
git checkout "$CURRENT_BRANCH" | |
cd "$WORKING_DIR" | |
fi | |
} | |
master_push() { | |
if git config --get 'branch.master.remote'; then | |
git_environment_vars | |
cd "$TOPLEVEL_DIR" | |
git checkout master | |
git push | |
git checkout "$CURRENT_BRANCH" | |
cd "$WORKING_DIR" | |
fi | |
} | |
sync_repo() { | |
master_update | |
master_push | |
} | |
branch_create() { | |
if [[ -z $1 ]]; then | |
echo 'Usage: branch_create <branchname>' | |
echo 'Creates a new branch named <branchname> with master as its start point' | |
else | |
git checkout -b "$1" master | |
fi | |
} | |
branch_update() { | |
master_update | |
git rebase master | |
} | |
# most commonly used; squash all branch commits into one | |
branch_merge() { | |
if branch_update; then | |
git_environment_vars | |
cd "$TOPLEVEL_DIR" | |
git checkout master | |
# validate that the merge happens since we have to forcefully delete the branch | |
if git merge --ff-only --squash "$CURRENT_BRANCH"; then | |
git commit --verbose --edit -m "$(echo "Squashed commit of the following:\n\n$(git log master..${CURRENT_BRANCH} --pretty=format:' * %ad %h - %s' --date=short)")" | |
git branch -D "$CURRENT_BRANCH" | |
fi | |
cd "$WORKING_DIR" | |
fi | |
} | |
# used for bigger branches; allows you to manually squash/fixup | |
# branch commits into smaller, more logical/manageable chunks | |
big_branch_merge() { | |
if branch_update; then | |
git_environment_vars | |
cd "$TOPLEVEL_DIR" | |
git rebase --interactive --autosquash master | |
git checkout master | |
git merge --no-ff --no-commit "$CURRENT_BRANCH" | |
git commit | |
cd "$WORKING_DIR" | |
fi | |
} | |
branch_log() { | |
git_environment_vars | |
echo "Commits in branch \"${CURRENT_BRANCH}\", but not \"master\":" | |
git log master..${CURRENT_BRANCH} --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative | |
} | |
branch_diff() { | |
git_environment_vars | |
echo "Commits in branch \"${CURRENT_BRANCH}\", but not \"master\":" | |
git diff master..${CURRENT_BRANCH} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment