Related
edit : I ended up upgrading to macOS Catalina yesterday and replacing bash with zsh. One thing that should be noted is that the stackcommand worked previously, but despite all the tinkering not ghci
After deleting all the files that had anything to do with Haskell, I retried running curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
This second time there was an error with the command line tools so I had to install them manually with xcode-select --install. After rerunning the curl, I added the path to the environmental file to my zsh profile manually with :
. "$HOME/.ghcup/env"\
echo '. $HOME/.ghcup/env' >> "$HOME/.zshrc"
Here is the content of the env file :export PATH="$HOME/.cabal/bin:/Users/agnel/.ghcup/bin:$PATH"
Now everything seems to be working (I never reinstalled stack, but I think I might leave that to the side while I learn the basics of the language).
I installed the Haskell Platform yesterday but am having a hard time getting it to work correctly.
The firsts steps I did are:
curl -sSL https://get.haskellstack.org/ | sh
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh
On step 1. the instructions said to append /Users/.../.local/bin the PATH variable (which I did in /etc/paths. On step 2, the script was supposed to pop up a dialog box (and didn't) when installing the necessary command line tools. It also said to rerun the script once complete (which I did). The script also said I should adjust my PATH variable, and source /Users/.../.ghcup/env in my shell configuration. It asked to this automatically but failed having not found the ~/.bashrc File. (I read that on Mac in contrary to linux, only .bash_profile is loaded upon opening of a terminal window so I adjusted the path variable there manually. I've spent forever messing around with the path variables and every time I try and run "$ ghci" I get the same -bash: ghci: command not found error message. If anyone has a solution to this problem I would be very grateful for an answer. If not, could someone with a working distribution of Haskell on their computer show me what their path variables look like?
Thanks!
A simple solution would just be to restart your terminal and you are good to go.
After installing the Haskell platform for the first time on a new mac with Catalina, I also got
~> ghci
zsh: command not found: ghci
What worked in my case was to use, instead of the plain ghci,
stack ghci
To get back the familiar behaviour, I created in my homedirectory a file named .zshrc containing
alias ghci='stack ghci'
If you open a new terminal, this file will automatically be executed.
I'd be interested to know if there is another solution.
Check if the ghcup command is working or not.
If not, make sure the .zshrc file has command for execution of ghcup. It should look something like this -
[ -f "/Users/myusername/.ghcup/env" ] && source "/Users/myusername/.ghcup/env" # ghcup-env
If the file exists, simply restarting terminal will work.
If it is still not working, set GHC as default using ghcup - follow this
I'm trying to run a CLI tool in Linux (Mint) which allows me to edit subtitles. It is named subedit: github link. In order to run it, I've added executable permission with chmod +x and added it to the path in bash. However, when I run it, I get the following error message:
bash: /home/main/Documents/shellTools/subedit/subedit: /usr/bin/bash: bad interpreter: No such file or directory
I'm not very experienced with external bash programs and forgot to do something that would be obvious in hindsight.
When I do echo $PATH this is the output:
/home/main/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/main/Documents/shellTools/subedit/
Could somebody please help?
Assuming bash is installed, (it usually is), change the first line of subedit from:
#!/usr/bin/bash
to:
#!/bin/bash
Or if one would prefer not to edit subedit, try this one-liner covering what Al-waleed Shihadeh suggested:
ln -s "$(which bash)" /usr/bin/bash
It seems that you don't have bash installed, you can verify that by running
which bash
if the above command returns "bash not found", then you need to install it.
In case the above command returns a path, you can use the below command to add a symlink to the expected path
ln -s $(path from the above command) /usr/bin/bash
Use the command termux-chroot ONCE!
If you want to always run at the start of a session, be sure to check if it was never run before.
if [ -z $CHROOT ]; then
CHROOT=1
termux-chroot
fi
E.g. on a fresh ubuntu machine, I've just run sudo apt-get git, and there's no completion when typing e.g. git check[tab].
I didn't find anything on http://git-scm.com/docs, but IIRC completion is included in the git package these days and I just need the right entry in my bashrc.
On Linux
On most distributions, git completion script is installed into /etc/bash_completion.d/ (or /usr/share/bash-completion/completions/git) when you install git, no need to go to github. You just need to use it - add this line to your .bashrc:
source /etc/bash_completion.d/git
# or
source /usr/share/bash-completion/completions/git
In some versions of Ubuntu, git autocomplete may be broken by default, reinstalling by running this command should fix it:
sudo apt-get install git-core bash-completion
On Mac
You can install git completion using Homebrew or MacPorts.
Homebrew
if $BASH_VERSION > 4: brew install bash-completion#2 (updated version)
Pay special care which version of bash you have as MacOS default ships with 3.2.57(1)-release.
add to .bash_profile:
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
For older versions of bash: brew install bash-completion
add to .bash_profile:
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
MacPorts
sudo port install git +bash_completion
then add this to your .bash_profile:
if [ -f /usr/share/bash-completion/bash_completion ]; then
. /usr/share/bash-completion/bash_completion
fi
more info in this guide: Install Bash git completion
Note that in all cases you need to create a new shell (open a new terminal tab/window) for changes to take effect.
i had same issue, followed below steps:
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
then add the following lines to your .bash_profile (generally under your home folder)
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
fi
source : http://code-worrier.com/blog/autocomplete-git/
Most of the instructions you see will tell you to download
https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
and source that in your bash startup script like .bashrc.
But there is a problem with that, because it is referencing the master branch, which is the latest version of git-completion.bash. The problem is that sometimes it will break because it is not compatible with the version of git you've installed.
In fact, right now that will break because the master branch's git-completion.bash has new features that requires git v2.18, which none of the package managers and installers have updated to yet. You'll get an error unknown option: --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config
So the safest solution is to reference the version/tag that matches the git you've installed. For example:
https://raw.githubusercontent.com/git/git/v2.17.1/contrib/completion/git-completion.bash
Note that it has a v2.17. in the URL instead of master. And then, of course, make sure to source that in the bash startup script.
Ubuntu 14.10
Install git-core and bash-completion
sudo apt-get install -y git-core bash-completion
For current session usage
source /usr/share/bash-completion/completions/git
To have it always on for all sessions
echo "source /usr/share/bash-completion/completions/git" >> ~/.bashrc
Just do this in your ~/.bashrc:
source /usr/share/bash-completion/completions/git
Other answers are telling you to install bash-completion, you don't need to do that, but if you do, then there's no need to source the completion directly. You do one or the other, not both.
A more generic solution is querying the system location as recommended by the bash-completion project:
source "$(pkg-config --variable=completionsdir bash-completion)"/git
See https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
You just need to source the completion script
on my ubuntu there is a file installed here:
source /etc/bash_completion.d/git-prompt
you can follow the links into the /usr/lib/git-core folder. You can find there an instruction, how to set up PS1 or use __git_ps1
macOS via Xcode Developer Tools
Of all the answers currently posted for macOS, this is only mentioned in a very brief comment by jmt...
If you already have the Xcode developer tools installed, then you shouldn't need to download anything new.
Instead, you just need to locate the already-existing git-completion.bash file and source it in your .bashrc. Check the following directories:
/Applications/Xcode.app/Contents/Developer/usr/share/git-core
/Library/Developer/CommandLineTools/usr/share/git-core
Failing that, git itself might be able to help you out. When I run git config as follows, git reports a setting which comes from a gitconfig file located in the same directory as my git-completion.bash:
$ git config --show-origin --list
...
file:/Applications/Xcode.app/Contents/Developer/usr/share/git-core/gitconfig credential.helper=osxkeychain
...
or you can always brute-force search your machine and grab some coffee:
$ find / -type f -name git-completion.bash 2>/dev/null
Thus, I have the following insertion for my ~/.bashrc:
# Git shell completion and prompt string on macOS
_git_dir="/Applications/Xcode.app/Contents/Developer/usr/share/git-core"
if [ -f "${_git_dir}/git-completion.bash" ]; then
source "${_git_dir}/git-completion.bash"
fi
if [ -f "${_git_dir}/git-prompt.sh" ]; then
source "${_git_dir}/git-prompt.sh"
fi
unset _git_dir
Note that this sources the git prompt-string script as well, since it resides in the same directory.
(Tested in macOS Catalina)
May be helpful for someone:--
After downloading the .git-completion.bash from the following link,
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
and trying to use __git_ps1 function, I was getting error as--
-bash: __git_ps1: command not found
Apparently we need to download scripts separately from master to make this command work, as __git_ps1 is defined in git-prompt.sh . So similar to downloading .git-completion.bash , get the git-prompt.sh:
curl -L https://raw.github.com/git/git/master/contrib/completion/git-prompt.sh > ~/.bash_git
and then add the following in your .bash_profile
source ~/.bash_git
if [ -f ~/.git-completion.bash ]; then
. ~/.git-completion.bash
export PS1='\W$(__git_ps1 "[%s]")>'
fi
source ~/.bash.git will execute the downloaded file and
export PS1='\W$(__git_ps1 "[%s]") command will append the checkout out branch name after the current working directory(if its a git repository).
So it will look like:-
dir_Name[branch_name] where dir_Name is the working directory name and branch_name will be the name of the branch you are currently working on.
Please note -- __git_ps1 is case sensitive.
Arch Linux
Source /usr/share/git/completion/git-completion.bash in one of the bash startup files.
For example:
# ~/.bashrc
source /usr/share/git/completion/git-completion.bash
You may be able to find the script in other locations like /usr/share/bash-completion/completions/git but these scripts did not work for me.
Mac M1
For those that are using Mac M1 environment, I was able to install via homebrew:
brew install bash-completion
Then added to my ~/.bash_profile or ~/.bashrc (whatever you use):
[[ -r "/opt/homebrew/Cellar/bash-completion/1.3_3/etc/profile.d/bash_completion.sh" ]] && . "/opt/homebrew/Cellar/bash-completion/1.3_3/etc/profile.d/bash_completion.sh"
You may need to update the version number (1.3_3). You'll just need to look it up in that directory. I would love to know if there's a better way.
Windows
How it works for me finally on Windows 10 command line (cmd):
Install Clink
Copy git-autocomplete.lua file into C:\Users\<username>\AppData\local\clink directory
Restart Windows
Ubuntu
There is a beautiful answer here. Worked for me on Ubuntu 16.04
Windows
Git Bash is the tool to allow auto-completion. Not sure if this is a part of standard distribution so you can find this link also useful.
By the way, Git Bash allows to use Linux shell commands to work on windows, which is a great thing for people, who have experience in GNU/Linux environment.
On Ubuntu 22.04 just add this line at the end of .bashrc or .zshrc
source /etc/bash_completion.d/git-prompt
On Github in the Git project, They provide a bash file to autocomplete git commands.
You should download it to home directory and you should force bash to run it. It is simply two steps and perfectly explained(step by step) in the following blog post.
code-worrier blog: autocomplete-git/
I have tested it on mac, it should work on other systems too. You can apply same approach to other operating systems.
Just put below in the .bashrc and relaunch the terminal. Navigate to Git repo to see the path in the prompt.
PS1='\[\033[0;32m\]\[\033[0m\033[0;32m\]\u\[\033[0;36m\] # \[\033[0;36m\]\h \w\[\033[0;32m\]$(__git_ps1)\n\[\033[0;32m\]└─\[\033[0m\033[0;32m\] \$\[\033[0m\033[0;32m\] ▶\[\033[0m\] '
After uninstall Docker on Ubuntu, each time I start a bash shell window, it emits the following hint:
The program 'docker' is currently not installed. You can install it by typing:
sudo apt install docker.io
I have searched in .bashrc, .profile, .bash_profile, but didn't found any lines related to docker.
So, how can I get rid of those tips?
Run PS4=':${BASH_SOURCE}:$LINENO+' bash -x -l -i to log every command in your startup scripts, including which config file or script they came from. Search through that, and you'll find the individual command that's creating this error.
(Note that very new versions of bash ignore inherited values of PS4 when running as root for security reasons. But you're not using root as your primary account... right?)
When using OSX’s git, after I modify a file I can simply do git commit <tab>, and that’ll auto complete the file’s name to the one that was modified. However, if I install a newer version of git from homebrew and I use it, that feature no longer works (meaning I press <tab> and it just “asks” me what file I want to do it on, even including the ones that have no changes).
Can anyone shed some light as to why, and how to solve that? I’d prefer using homebrew’s git, since it’s more up-to-date.
My shell is zsh, and Neither installing bash-completion or zsh-completions worked (even after following homebrew’s post-install instructions).
Also, after installing git with homebrew it says
Bash completion has been installed to: /usr/local/etc/bash_completion.d
zsh completion has been installed to: /usr/local/share/zsh/site-functions
So shouldn’t I be able to use one of those?
You're looking for:
brew install git bash-completion
As warpc's comment states, you'll need to add the following to your ~/.bash_profile to get homebrew's bash-completion working:
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
The above is mentioned in the caveats when you install the bash-completion formula.
Note: if you are using Bash v4 or later (via brew install bash) then you're going to want to use brew install bash-completion#2, to enable tab completion add the following to ~/.bash_profile as described in the caveats:
export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d"
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
The additional export is necessary for git, docker, youtube-dl, and other completions which may be included in the $(brew --prefix)/etc/bash_completion.d/ directory.
This get's git tab completion working on OSX without having to restart your terminal:
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash
echo "source ~/.git-completion.bash" >> ~/.bash_profile
source ~/.bash_profile
EDIT: this doesn't work in Catalina's default zsh shell. I changed the default shell back to bash and it works again. https://www.howtogeek.com/444596/how-to-change-the-default-shell-to-bash-in-macos-catalina/
In case anyone else makes my dumb mistake, try brew install git. I was using the git that comes with Xcode and didn't realize that I had never installed Homebrew's git to get the autocompletions.
for some reason I was missing the file at $(brew --prefix)/etc/bash_completion so #Graham Perks' correct answer didn't work for me
It ended up the fix in my case was:
brew unlink bash-completion
brew link bash-completion
I solved the problem by figuring out that $(brew --prefix)/etc/bash_completion returned Permission denied when executed. So after a simple:
chmod +x $(brew --prefix)/etc/bash_completion
Everything is now working fine. I'm wondering why Homebrew doesn't make the bash_completion file executable on installation, though.
For bash on macOS Catalina (3/30 update: Big Sur too), if you want to also use Bash 5 from homebrew, you need to make sure that your login shell is set to homebrew's bash, and not the default.
To check if you need to do this, run echo ${BASH_VERSION}. If you see a version starting with 3, you are not using Brew's bash for your login shell.
To change this,
Open System Preferences->Users and Groups.
Right click your user and select "Advanced Options". You may need to unlock this with your password by clicking the lock in the bottom left.
Set the login shell field to the location of your brew's bash, which you can usually find by running which bash in a terminal after you install brew's bash. Mine was /usr/local/bin/bash.
Restart your terminal, and follow the instructions in this excellent answer
Found a working solution. It's very recent (authored 16 hours ago, and committed 2 hours ago), and it comes directly from homebrew.
brew install git --without-completions
Just tried it, and it finally works as intended.
I had the same issue and even found this post this morning. I fixed the issue by updating brew with brew update and then reinstalling git with brew reinstall git.
I was then notified of another file that is blocking the homebrew linking process, in my case it was /usr/local/share/zsh/site-functions/git-completion.bash. Removing the file and running brew link git solved the issue. Guessing it was just a bad recipe version we stumbled upon.
If you have $BASH_VERSION < 4.1, eg 3.2.57(1)-release then go ahead with:
brew install bash-completion
# In ~/.bash_profile :
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
However if you've brew install bash to get version 4.4.12(1)-release
you can use the better and more complete completions in:
brew install bash-completion#2
# In ~/.bash_profile:
[ -f "$(brew --prefix)/share/bash-completion/bash_completion" ] \
&& . "$(brew --prefix)/share/bash-completion/bash_completion"
Note that some packages (brew, docker, tmux) will still put some completions into $(brew --prefix)/etc/bash_completion.d/ so you might add:
for completion in "$(brew --prefix)/etc/bash_completion.d/"*
do
. $completion
done
Finally you should be able to add the git completion script if for some reason the way you installed git did not add it to either of those:
[[ -f $(brew --prefix)/etc/bash_completion.d/git \
|| -f $(brew --prefix)/share/bash-completion/completions/git ]] \
|| curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash \
-o $(brew --prefix)/etc/bash_completion.d/git
You can get and add it with the above.
Step 1: Download auto completion script:
cd ~
curl -O https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash
Step 2: Update .bash_profile and .bashrc
echo "source ~/git-completion.bash" >> .bash_profile
Via https://www.anintegratedworld.com/git-tab-autocomplete-on-osx-10-11-el-capitan/
If above does not work, try https://github.com/bobthecow/git-flow-completion/wiki/Install-Bash-git-completion
In 2019, using Bash v5, you do not need to explicitly source the git bash completion script in your .bash_profile or .bashrc
Ensure you have the following two lines in your .bashrc
export BASH_COMPLETION_COMPAT_DIR="/usr/local/etc/bash_completion.d"
[[ -r "/usr/local/etc/profile.d/bash_completion.sh" ]] && . "/usr/local/etc/profile.d/bash_completion.sh"
Download the git bash completion script (https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash) and save it to /usr/local/etc/bash_completion.d/ as git
That's it! Bash will automatically pick up the git completion file and enable completion.
Side Note: I recommend putting all these changes in .bashrc as this ensures that when you drop into an interactive shell (ie. from pipenv shell), completions will get loaded correctly as bash will source .bashrc and NOT .bash_profile.
For me , I had to put
source $(brew --prefix)/etc/bash_completion
into .bashrc (not .bash_profile) to get this to work.
".bash_profile is executed for login shells, while .bashrc is executed
for interactive non-login shells" -- from What is the difference between .bash_profile and .bashrc? It appears to me that MacOS Sierra doesn't execute .bash_profile when opening a new terminal window, only .bashrc.
I wouldn't put it in _bash_profile, because then I'd have to reboot/logout for updates to take effect.
This worked for me in Mojave (OSX 10.14.1):
brew install bash-completion
Then add the following line to your ~/.bash_profile:
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion
It may have something to do with libedit being used instead of readline in Lion.
Try installing readline before git.
brew install readline
For those who already have brew bash-completion installed. I did not have the git completion script installed and could not find any tap for that.
So I added it manually:
curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o $(brew --prefix)/etc/bash_completion.d/git
Note that you have to rename the file and remove the extension for it to work.
If you do not have completion or git installed, install it in the accepted answer.
brew install git bash-completion
If you used homebrew to install git, then probably there is no need to install anything to support git completion.
"git-completion.bash" file is somewhere (mine was here: /usr/local/git/contrib/completion/git-completion.bash)
All you need to do is to find the file:
sudo find / -type f -name "git-completion.bash"
Then source its path in your .bash_profile.
For example I needed to add this line to my ~/.bash_profile:
source /usr/local/git/contrib/completion/git-completion.bash
Don't forget to source your ~/.bash_profile or reopen your terminal ;)
from:
how-enable-git-tab-completion-bash-mac-os-x
I know this is an old post, but you don't really need to install any additional packages.
Homebrew is informing you that there is a directory with all the stuff you need.
You can simply add the following line to your .bash_profile if you are using Bash:
source /usr/local/etc/bash_completion.d/git-completion.bash
If nothing works, it could be because you have an older version of bash and bash completion script is not getting sourced by the /usr/local/etc/profile.d/bash_completion.sh script. You can test this by adding a simple echo inside the conditionals in file /usr/local/etc/profile.d/bash_completion.sh:
10 if shopt -q progcomp && [ -r /usr/local/Cellar/bash-completion#2/2.11/share/bash-completion/bash_completion ]; then
11 # Source completion code.
echo "doing bash completion or not"
12 . /usr/local/Cellar/bash-completion#2/2.11/share/bash-completion/bash_completion
And open a new terminal. If you don't see the echo message, then the conditionals do not evaluate to true. In my case it was because the bash version was old, the default from mac 3.2.blah.
I did install a newer bash from brew, but i forgot to chsh and that caused me a lot of headache. bash --version would return 5.1.8 but the enabled shell was still the old one :) To test the enabled bash you can do
for n in {0..5}
do
echo "BASH_VERSINFO[$n] = ${BASH_VERSINFO[$n]}"
done
The fix was to sudo chsh -s /usr/local/bin/bash After which the completions worked.
After tearing my hair out over this one for ages, I discovered that when I had the hub command installed, the completions for the hub command were breaking the completions for git. I had to remove /usr/local/etc/bash_completion.d/hub.bash_completion.sh. This meant no completions for hub, but git completions now worked. I didn't debug why this was.
I had the following brew packages installed:
bash: 5.1.16
bash-completion#2: 2.11
git: 2.35.1
hub: 2.14.2
Enable Auto Completion of GIT commands on MAC-OS Mojave 10.14
I am a developer and use GIT from the command line all of the time. When I consider the development perspective, I used to execute a lot of commands using the command line for GIT operations. Most of the time it is very annoying that MAC OS doesn't have automatic support for the command completion which I partially support. as well as the command suggestions, which means what are the commands available for typed characters. So it is very troublesome to type very long command and mostly repetitive task as typo going wrong. :(
Tab completion would certainly be faster and easier. Unfortunately, the default installation of git on some Mac computers doesn't have tab completion enabled.
So that I was searching for a fix for the problem and there are several solutions found from the web search such as StackOverflow, GitHub as well as from the medium. Unfortunately, those solutions did not work for me and got frustrated with trying different solutions so many times.
I was searching deeply and trying out different solutions and fortunately, it is an easy fix. Below are the steps I have collected from several posts and finally it worked as expected. So I hope to share with others who have this problem like me.
f you go to the web search and you can find many solutions which mentioned the git completion bash file. Even GitHub guide as well. But I suggest you check first if the git-completion.bash file is already in your MAC computer with the git-core or something else which came from installation. you can use below command.
sudo find / -type f -name "git-completion.bash"
you will get below results. (may have some difference according to the content)
/Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash
/Users/Dilanka/git-completion.bash
/Users/Dilanka/.oh-my-zsh/plugins/gitfast/git-completion.bash
/Users/Dilanka/Downloads/git-completion.bash
I suggest you to pick which installed from git-core
If the git-completion.bash script doesn't exist on your machine, please retrieve it from the below provided above and save it to your local machine in a new file called git-completion.bash in the /usr/local/etc/bash_completion.d/ directory.
https://git-scm.com/book/en/v1/Git-Basics-Tips-and-Tricks
If you use the Bash shell, Git comes with a nice auto-completion script you can enable. Download it directly from the Git source code at
https://github.com/git/git/blob/master/contrib/completion/git-completion.bash
If the git-completion.bash script exists on your machine, but is not in the /usr/local/etc/bash_completion.d/ directory, you should create that directory and copy the file into it. Below command will do the job:
sudo mkdir /opt/local/etc/bash_completion.d
sudo cp /Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash /usr/local/etc/bash_completion.d/git-completion.bash
After the completion of above. The git-completion.bash script should exist on your local machine in the/usr/local/etc/bash_completion.d/ directory.
Now you need to refresh your profile using below command. It will load your added bash file to the terminal context.
source ~/.bash_profile
Great!!! you have done it. Just start the terminal window and try it. Just type "git sta" it will show suggestions as below:
git sta
stage stash status
git chec<TAB> will show git checkout
see my GitHub post here:
https://github.com/DIL8654/Enable-Auto-Completion-of-GIT-commads-on-MAC-OS-Mojave
See my Medium post here:
https://medium.com/#dilanka85/enable-auto-completion-of-git-commands-on-mac-os-mojave-10-14