How to enable Git Autocomplete in MacOS?
Asked Answered
V

1

25

I'm using Mac OS Monetary and Recently installed Git for a project. I followed the below steps to activate the Git Autocomplete feature for Git commands and Branch names. I got success in my Previous Macbook with MacOS Catalina, but it's not working on Monetary. The Error is, "zsh: permission denied: /Users/username/.zshrc" when I run "~/.zshrc"

Steps Are:

Run in Terminal

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

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

~/.zshrc

Update the File with

zstyle ':completion:*:*:git:*' script ~/.zsh/git-completion.bash
fpath=(~/.zsh $fpath)

autoload -Uz compinit && compinit

And Run

source ~/.zshrc

How can I solve this?

Vardon answered 17/8, 2022 at 18:6 Comment(1)
Not sure where you got these instructions from but this appears to be trying to use the bash completion with zsh. Zsh comes with git completion and the only thing needed to enable it is the final line in .zshrc, i.e autoload -Uz compinit && compinitDizon
P
57

I edited the file with vim

sudo vim ~/.zshrc

provide your password and add the following to the end of the file

autoload -Uz compinit && compinit

relaunch your shell and you should have git completions

git checkout my_branch<tab>

should tab complete the branch name for you.

Precondemn answered 6/1, 2023 at 0:7 Comment(2)
Can you please explain about the used commands?Camelliacamelopard
sudo and git are pretty common. autoload is a zsh / korn shell thing. Read man zshbuiltins linux.die.net/man/1/zshbuiltins > Equivalent to functions -u, with the exception of -X/+X and -w. The flag -X may be used only inside a shell function, and may not be followed by a name. It causes the calling function to be marked for autoloading and then immediately loaded and executed, with the current array of positional parameters as arguments. This replaces the previous definition of the function. If no function definition is found, an error is printed and the function remainsPrecondemn

© 2022 - 2024 — McMap. All rights reserved.