Move Git aliases to subcommand scripts

Any executable script on you PATH
that is named `git-some-name`
will be available as a git subcommand,
which means you could do `git some-name` to run the script.

Git adds them to `git help -a` under the title
"git commands available from elsewhere on your $PATH",
which will then power the auto completion,
so that will also work for any command you add.

http://blog.zamith.pt/blog/2014/11/05/supercharging-your-git/

Examples of other projects that structure their dotfiles like this:

https://github.com/robbyrussell/oh-my-zsh
https://github.com/tj/git-extras
https://github.com/holman/dotfiles
This commit is contained in:
Dan Croak 2015-04-11 18:57:50 -07:00
parent 266984354b
commit 24b34d1bec
10 changed files with 57 additions and 9 deletions

6
bin/git-co-pr Executable file
View file

@ -0,0 +1,6 @@
#!/bin/sh
set -e
git fetch origin "pull/$1/head:pr/$1"
git checkout "pr/$1"

9
bin/git-create-branch Executable file
View file

@ -0,0 +1,9 @@
#!/bin/sh
set -e
git push origin "HEAD:refs/heads/$1"
git fetch origin
git branch --track "$1" "origin/$1"
cd .
git checkout "$1"

6
bin/git-ctags Executable file
View file

@ -0,0 +1,6 @@
#!/bin/sh
set -e
[ -f .git/hooks/ctags ] || git init
.git/hooks/ctags

5
bin/git-current-branch Executable file
View file

@ -0,0 +1,5 @@
#!/bin/sh
set -e
git rev-parse --abbrev-ref HEAD

6
bin/git-delete-branch Executable file
View file

@ -0,0 +1,6 @@
#!/bin/sh
set -e
git push origin :refs/heads/"$1"
git branch --delete "$1"

6
bin/git-merge-branch Executable file
View file

@ -0,0 +1,6 @@
#!/bin/sh
set -e
git checkout master
git merge "@{-1}"

5
bin/git-pr Executable file
View file

@ -0,0 +1,5 @@
#!/bin/sh
set -e
hub pull-request

8
bin/git-rename-branch Executable file
View file

@ -0,0 +1,8 @@
#!/bin/sh
set -e
old=$(git current-branch)
git branch -m "$old" "$1"
git push origin --set-upstream "$1"
git push origin --delete "$old"

6
bin/git-up Executable file
View file

@ -0,0 +1,6 @@
#!/bin/sh
set -e
git fetch origin
git rebase origin/master "$@"

View file

@ -11,16 +11,7 @@
ca = commit --amend -v
ci = commit -v
co = checkout
co-pr = !sh -c 'git fetch origin pull/$1/head:pr/$1 && git checkout pr/$1' -
create-branch = !sh -c 'git push origin HEAD:refs/heads/$1 && git fetch origin && git branch --track $1 origin/$1 && cd . && git checkout $1' -
ctags = "!sh -c '[ -f .git/hooks/ctags ] || git init; .git/hooks/ctags' git-ctags"
current-branch = !sh -c 'git rev-parse --abbrev-ref HEAD' -
delete-branch = !sh -c 'git push origin :refs/heads/$1 && git branch -D $1' -
merge-branch = !git checkout master && git merge @{-1}
pr = !hub pull-request
rename-branch = !sh -c 'old=$(git current-branch) && git branch -m $old $1 && git push origin --set-upstream $1 && git push origin --delete $old' -
st = status
up = !git fetch origin && git rebase origin/master
[core]
excludesfile = ~/.gitignore
autocrlf = input