Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Follow some instruction on this site http://denis.tumblr.com/post/71390665/adding-bash-completion-for-git-on-mac-os-x-leopard . I can do git auto complete for MAC OS. However, when I type git pull origin ma (for master), and then tab it takes a long time for git to auto complete to become git pull origin master . I think it connect to the server to get the branch, but I am not sure, is there any way to make it faster and only get the branch on local machine

cd /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
share|improve this question

1 Answer 1

This is necessary by design. When you are performing a git-pull, the branch name you are pulling from is a remote branch. It has no choice but to contact the remote repository in order to get the list of possible completions.

You can prove this to yourself if you try to auto-complete a git-push command. Completing the branch name master will be much quicker because you are pushing a local branch, so you won't need to contact the remote repository.


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.)

share|improve this answer
    
so in other words, for the git-pull, train oneself to type out the branch name if one knows it, and rely on autocomplete only if one doesn't. nice explanation, thanks! –  quack quixote May 5 '10 at 5:17
    
Yeah, thanks a lot. Really clear explanation. Usually, in our company, the remote and local branch have the same name. I think it would be good if we folow a convention that : if the name are the same, use auto complete, if not, they have to type it –  vodkhang May 5 '10 at 5:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.