Меню Рубрики

Git autocomplete mac os

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.

  1. If 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 pick which installed from git-core

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

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

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

4. After the completion of step 3. The git-completion.bash script should exist on your local machine in the/usr/local/etc/bash_completion.d/ directory.

5. Now you need to refresh your profile using below command. It will load your added bash file to the terminal context.

Great. you have done it. Just start the terminal window and try it. Just type “git sta” it will show suggestions as below:

Источник

Autocomplete Git commands and Branch names in Terminal on Mac OS X

If you are a user of Git on Mac OS X then sometimes it can become annoying that you cannot autocomplete the Git commands and branch names.

Luckily there is a way to fix this simple problem:

1. First step is to execute this command in your terminal window, this is basically grabbing the ‘git-completion.bash’ script and putting it in your home directory.

2. Now add this line to your ‘

/.bash_profile’. This will allow the execution of the git autocomplete script if it present

3. You can now restart all you terminal windows or just refresh the terminal window you wish to use this script in. To refresh do:

You are all done now! Now type ‘git’, ‘space’, ‘tab’, you’ll get a list of all the possibilities. Same thing if you do ‘git checkout tab’ or ‘git checkout first few letters of branch name tab’.

Источник

git auto-complete for *branches* at the command line?

On my Linux machine I have autocomplete for branches with Git.

[Note we are talking about git branch completion, not bash completion (e.g. commands, files, etc). Thus NOT Lane’s answer at all]

For example I can type git checkout + TAB and get a list of branches.

Or I can type git checkout feb* + TAB to get all branches that begin with «feb».

How can I get this functionality on a Mac?

I tried downloading and running bash-completion/bash_completion and bash-completion/bash_completion.sh.in but no joy. The first gave error messages about declare: -A invalid_option . The second gave no errors. When I git checkout + TAB though I am still getting a list of files in the directory, not branches. I am in the project root.

Auto-complete for directories and bash commands are working ok, so it’s specific to Git.

14 Answers 14

ok, so I needed the git autocompletion script.

I got that from this url:

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

No need to worry about what directory you’re in when you run this as your home directory(

) is used with the target.

Then I added to my

/.bash_profile file the following ‘execute if it exists’ code:

Update: I’m making these bits of code more concise to shrink down my .bashrc file, in this case I now use:

Note: $_ means the last argument to the previous command. so . $_ means run it — «it» being .git-completion.bash in this case

This still works on both Ubuntu and OSX and on machines without the script .git-completion.bash script.

Now git Tab (actually it’s git Tab Tab ) works like a charm!

p.s.: If this doesn’t work off the bat, you may need to run chmod u+x

/.git-completion.bash to grant yourself the necessary permission:

  • chmod is the command that modifies file permissions
  • u means the user that owns the file, by default its creator, i.e. you
  • + means set/activate/add a permission
  • x means execute permission, i.e. the ability to run the script

/.bash_profile after pasting the code. Restarting the terminal will also do the same thing. – Ben Feb 2 ’17 at 17:56

]] [—html-path] [—man-path] [—info-path] [-p | —paginate | —no-pager] [—no-replace-objects] [—bare] [—git-dir=

] [—namespace= ] [] – Sachin Oct 9 ’18 at 10:28

Some people prefer to use a package manager to automate the installing, updating, and configuring of Mac OS packages. I am a fan of package managers, and I think Homebrew is the best package manager for Mac OS (some would say it’s the de-facto Mac OS package manager).

Once you have installed Homebrew, you can simply install git along with bash-completion with brew install git bash-completion .

You’ll then need to put the following in your

(Note: If this install fails with a 404 error, and you already have git installed, just remove the git part of this brew install)

/.bash_profile ? – Vikas Bansal Jul 18 ’17 at 11:47

Run this on terminal:

That’s all. This worked for me.

/.bash_profile file doesn’t exist. That’s fine just create the file and place that if script in there and save. Reload your shell after and it will work. – agm1984 Oct 19 ’18 at 19:32

/.bash_profile – Imran Feb 5 at 18:51

git and git-completion.bash already come with macOS command line tools ( xcode-select —install ). To enable bash autocomplete, add this to your

This will also enable autocomplete for git branches.

Here’s what’s confusing some of you: you have brew or ports installed, but you are using an the system git in /usr/bin/ . To check this:

If you see /usr/bin/git then either brew isn’t correctly configured, or you’ve not installed git via brew.

If you install git via brew, then enabling bash completions for brew will also enable bash completions for git. This is because /usr/local/etc/bash_completion actually sources everything in /usr/local/bash_completion.d , and the brew package for git installs a git completion script there.

You could install bash and git from MacPorts with the «bash_completion» option enabled. It is probably the easiest way of maintaining both git and the completions up-to-date.

Additional info

As for locating the completion settings on your Linux system, have a look in /etc/bash_completion.d/git (it is a long file). Copying that by itself probably won’t work, though, as it is designed to be sourced by the completion framework through /etc/bash_completion (which is sourced from /etc/profile.d/bash_completion.sh; files in /etc/profile.d are sourced from /etc/profile).

If your git completion is partially broken, even after sourcing https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash , you may just need to update your git version.

For example, when I typed git check + TAB , it would correctly autocomplete git checkout . But when I typed git checkout + TAB , it did not display the list of branches, only HEAD .

The fix for me was to update my git version. I was on 2.7.0, which apparently was not compatible with the latest git-completion.bash . I ran brew upgrade git , which updated it to 2.13.0, and now it properly autocompletes my branch names.

By far, the best reference I’ve found to solve this very issue is on SpinDance, by Connor Livingston:

If the git-completion.bash script doesn’t exist on your machine, please retrieve it from the link I provided above (which is this) and save it to your local machine in a new file called git-completion.bash in the /usr/local/etc/bash_completion.d/ directory. If the git-completion.bash script exists on your machine, but is not in the /usr/local/etc/bash_completion.d/ directory, we should create a copy of it in that directory. A quick sudo cp /current/path/to/your/git-completion.bash /usr/local/etc/bash_completion.d/git-completion.bash should do the trick. For those who are curious about the /usr/local/etc/bash_completion.d/ directory: it’s for storing new completion commands, and you may have to create it if it doesn’t already exist on your machine.

At this point the git-completion.bash script should exist on your local machine in the /usr/local/etc/bash_completion.d/ directory. Now we’ll plug the git completion script into bash by pointing to it from

Note: the tilde in the previous sentence refers to the home directory on your computer. Add the following line to

/.bash_profile: source /usr/local/etc/bash_completion.d/git-completion.bash and save. The final step is to reload your bash profile. You can achieve this by running source

/.bash_profile in your current bash session.

Источник

Добавить комментарий

Ваш адрес email не будет опубликован. Обязательные поля помечены *

  • Gimp для mac os на русском
  • Gimp for mac os x
  • Gif brewery mac os
  • Geometry dash mac os
  • Geforce gtx 1050 mac os x