Git auto and tips (windows + OS X)
vi ~/.gitconfig
[user]name = Khang Voemail = vodkhang@gmail.com[color]ui = auto
[alias]
st = status
ca = commit -am
br = branch
co = checkout
lg = log -p
au = add -u
l = pull
s = push
Reference:https://git.wiki.kernel.org/index.php/Aliases
3/ Bash shell auto-completion
In Windows, auto completion is by default, in Mac OS, you have to manuall set it up to have auto completion. These steps will help you to have an auto complete git on your MAC machine. It also display the current branch when you are in a git repository.
Put the following linecd
/tmp
git clone git://git.kernel.org/pub/scm/git/git.git
cd
git
git checkout v
`
git --version | awk
'{print $3}'
`
cp contrib/completion/git-completion.bash ~/.git-completion.bash
cd
~
rm -rf /tmp/git
echo
-e
"source ~/.git-completion.bash"
>> .profile
vim .profile
PS1='\u@\h:\W$(
__git_ps1 " (%s)")\$ '
Then restart your terminal
4/ Pull/Push auto-completion
By default, the git pull auto complete will contact with server. If you want to make auto-complete always complete using local branch names, then you can change the behavior.
This might only be useful if your local branch names are identical to remote branch names.
Edit the file ~/.git-completion.bash
and around line 458, look for this code:
fetch)
if [ $lhs = 1 ]; then__gitcomp "$(__git_refs2 "$remote")" "$pfx" "$cur"
else
__gitcomp "$(__git_refs)" "$pfx" "$cur"
fi
;;
pull)
if [ $lhs = 1 ]; then
__gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
else
__gitcomp "$(__git_refs)" "$pfx" "$cur"
fi
;;
push)
if [ $lhs = 1 ]; then
__gitcomp "$(__git_refs)" "$pfx" "$cur"
else
__gitcomp "$(__git_refs "$remote")" "$pfx" "$cur"
fi
;;
esac
…and change it to this:
fetch)
if [ $lhs = 1 ]; then __gitcomp "$(__git_refs)" "$pfx" "$cur" else __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur" fi ;; pull) if [ $lhs = 1 ]; then __gitcomp "$(__git_refs)" "$pfx" "$cur" else __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur" fi ;; push) if [ $lhs = 1 ]; then __gitcomp "$(__git_refs)" "$pfx" "$cur" else __gitcomp "$(__git_refs "$remote")" "$pfx" "$cur" fi ;; esac
(Notice that we changed the “fetch” and “pull” sections to use the same logic as “push”. This means it will be looking for local branch names instead of remote branches.)
Reference: http://superuser.com/questions/137689/git-pull-auto-complete-osx
1 comment