profile-git 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. git-ignore() {
  2. local site="https://raw.githubusercontent.com/github/gitignore/master"
  3. if [[ $1 == "--global" ]]; then
  4. shift
  5. ignore_file=${HOME}/.gitignore_global
  6. site+="/Global"
  7. else
  8. ignore_file="./.gitignore"
  9. fi
  10. wget -qO- "${site}/${1}.gitignore" >> "${ignore_file}"
  11. }
  12. git-create() {
  13. mkcd "${1}"; shift
  14. git init
  15. touch .gitignore
  16. local message="Initializing repository"
  17. if [[ $# -ge 1 ]]; then
  18. for i in "$@"; do git-ignore "${i}"; done
  19. message+=" with ignore lists: [ $1"
  20. [[ $# -eq 1 ]] || message+="$(printf ", %s" "${@:2}")"
  21. message+=" ]"
  22. fi
  23. maybe_do git-ignore-local
  24. git add .gitignore
  25. git commit -m "${message}"
  26. }
  27. git-sync-release() {
  28. rel="release/${1}"
  29. br="$(git branch | grep '^\*' | cut -c3-)"
  30. # Confirm that this is a real branch
  31. (git branch -r | grep "${rel}" &>/dev/null) || return 1
  32. # Merge dev
  33. # Make sure that we're not doing a weird clobber
  34. git checkout "${rel}" || return 2
  35. # Sanity check...
  36. git pull
  37. git merge --ff-only origin/dev || return 3
  38. # Update origin:release
  39. git push
  40. git checkout "${br}"
  41. # Don't delete if we're on this branch
  42. [[ "${br}" == "${rel}" ]] || git branch -D "${rel}"
  43. }
  44. alias git-graph="git log --graph --pretty=oneline --abbrev-commit --decorate --all"
  45. alias git-history-graph="git log --graph --pretty='format:%C(auto)%h (%<(50,trunc)%s, %ad)%d' --abbrev-commit --decorate --all"
  46. git-weeks-ago() {
  47. weeks="${1:-1}"
  48. end="$(date +"%Y-%m-%d" --date="${weeks} weeks ago Sunday")"
  49. begin="$(date +"%Y-%m-%d" --date="$((weeks+1)) weeks ago Sunday")"
  50. echo "--after ${begin} --before ${end}"
  51. }
  52. alias git-cleanup='(git branch --merged | egrep -v "(^\*|^\+|master|dev)" | xargs git branch -d); (git fetch --prune 2>&1 | grep deleted | sed "s/.*-> origin\///" | xargs git branch -D)'