Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git-completion, OS X, Homebrew instructions #46

Open
thomasaw opened this issue Apr 10, 2016 · 22 comments
Open

git-completion, OS X, Homebrew instructions #46

thomasaw opened this issue Apr 10, 2016 · 22 comments

Comments

@thomasaw
Copy link

thomasaw commented Apr 10, 2016

For more recent versions of git (installed via brew), the shell script should be:

if [ -f `brew --prefix`/etc/bash_completion.d/git-completion.bash ]; then
  . `brew --prefix`/etc/bash_completion.d/git-completion.bash
fi

@erikhuizinga
Copy link

Does not work on my macOS Sierra with Git version 2.9.3 (Apple Git-75). I get errors:

-bash: __git_find_subcommand: command not found
-bash: __gitcomp: command not found

@manodupont
Copy link

WEll for me there is just nothing. So i added the git-flow-completion.bash into /etc/bash_completion.d folder.

i added this script to my .bash_profile

if [ -f `brew --prefix`/etc/bash_completion.d/git-flow-completion.bash ]; then
  . `brew --prefix`/etc/bash_completion.d/git-flow-completion.bash
fi

then reload bash

source ~/.bash_profile

Then what ? No auto completion at all! What am i missing ?

@thomasaw
Copy link
Author

thomasaw commented Apr 7, 2017

@erikhuizinga @manodupont My suggestion only works when you install git via brew. (I recommended installing it via brew because you can get the latest version easier.)

@manodupont
Copy link

manodupont commented Apr 7, 2017 via email

@thomasaw
Copy link
Author

thomasaw commented Apr 7, 2017

When installed with brew the full path should be: /usr/local/etc/bash_completion.d/git-flow-completion.bash. It should be installed there when you install git (via brew).

@erikhuizinga
Copy link

erikhuizinga commented Apr 7, 2017 via email

@kwelch
Copy link

kwelch commented May 5, 2017

I was able to fix this by relinking the newest.

brew install git && brew link --overwrite git

@alicederyn
Copy link

I had to brew uninstall git then brew install git, perhaps because git was installed before bash_completion and there were no updates to pick up.

@dnetix
Copy link

dnetix commented Sep 28, 2017

I just made it work!
First install with brew bash-completion just running brew install bash-completion

Then download this two files
git-completion.bash
git-flow-completion.bash

Now copy them to the folder BREW_PREFIX/etc/bash_completion.d/ typically BREW_PREFIX is /usr/local but you can figure out which one is yours just running the command brew --prefix
And lastly copy this instructions to your ~/.profile file

if [ -f $(brew --prefix)/etc/bash_completion ]; then
  . $(brew --prefix)/etc/bash_completion
fi
if [ -f $(brew --prefix)/etc/bash_completion.d/git-completion.bash ]; then
  . $(brew --prefix)/etc/bash_completion.d/git-completion.bash
fi
if [ -f `brew --prefix`/etc/bash_completion.d/git-flow-completion.bash ]; then
  . `brew --prefix`/etc/bash_completion.d/git-flow-completion.bash
fi

Close the terminal or source the .profile file to enable autocompletion
And now you can use tab to autocomplete commands on git

@adrian2x
Copy link

@dnetix Your solution worked for me too (Sierra 10.12.6)
How comes those files are not downloaded automatically by bash though?

@jack829
Copy link

jack829 commented Feb 2, 2018

@dnetix Thank you!!! Finally works. I'd been trying half-heartedly to get this working for a couple months and kept giving up.

@GuanglinDu
Copy link

GuanglinDu commented Feb 4, 2018

@dnetix Many thanks for your solution. It works great. I've been annoyed by this Git-cannot-autocomplete for about 3 months after starting my journey on Mac OS (Sierra 10.12.6 + Git 2.14.3).

By the way either 'source ~/.bash_profile' or 'exec -l $SHELL' enables the autocompletion.

@Irrizzit
Copy link

another update to this little gem.
thanks

@patriciafrias
Copy link

Thank you soooo much @dnetix. Finally it works!!!!

@ghost
Copy link

ghost commented Aug 2, 2018

My usage

  • brew install bash bash-completion@2 and set it as my shell
  • put completion script to ~/.local/share/bash-completion/completions/<command_name> for lazy loading
    • the script is not loaded until I TAB on the command
    • use a jumper script if needed

e.g. a jumper script

# file: ~/.local/share/bash-completion/completions/git
if [ -f /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash ]; then
    . /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash
fi

@YellowPlusX
Copy link

@dnetix thank you for your solution.It works for me.

@spen
Copy link

spen commented Dec 19, 2018

+1 hat tip for this 👌

@MBerger1
Copy link

+1 - ty @dnetix !!

@nattsdaff
Copy link

finally!!! Thank you @dnetix

@scoreytime
Copy link

Thank you @dnetix! This worked great for me on OS Catalina 10.15.1

knightofiam added a commit to knightofiam/dotfiles that referenced this issue Nov 10, 2020
- Requires bash-completion (installed via Homebrew).

- git-completion.bash must be manually downloaded from:

    https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash

  and copied to:

    $(brew --prefix)/etc/bash_completion.d/

- See bobthecow/git-flow-completion#46 for
  more information.
@ahmedhamdy2121
Copy link

Nono of the above worked for me :(

I am using macOS Catalina version 10.15.7 (19H114)

@dnetix your solution gives me this error /usr/local/etc/bash_completion:1577: command not found: complete when running source ~/.bash_profile

Anyone can help?

@chadfurman
Copy link

This is quite ancient -- the .bash script is now considered deprecated, apparently -- zsh is now the default terminal on OSX it seems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests