Speed Up GitHub CLI: Custom Completion for 'gh repo clone' Command
Ever found yourself typing gh repo clone
and struggling to remember repository names? I’ve been there. As a developer who works with dozens of repositories daily, I needed a better solution. That’s why I created a custom completion script that makes the GitHub CLI’s clone command more powerful and user-friendly.
Why Custom Completion Matters
While the standard gh repo clone
is incredibly useful, it lacks intelligent autocompletion. Here’s what you’re missing:
$ gh repo clone my<tab>
my-awesome-project my-docker-images my-python-scripts
I struggled to recall exact repository names, some of which are a mouthful. Then there were the flags that I could never remember. These tiny hurdles added up, hindering productivity, especially for those who constantly work with multiple repositories.
Driven by the desire for seamless interaction, I embarked on a quest to enhance my command-line experience. Instead of wrestling with repository names and flags, I decided to create a custom completion script for the gh repo clone
command. The script enables:
- Smart Repository Suggestions: Instantly see matching repositories as you type.
- Flag Completion: Access additional
git clone
options forgh repo clone
by pressingtab
twice after the--
flag.
The completion script automatically populates suggestions, enabling faster interaction and execution with the GitHub CLI.
Common Use Cases
# Clone only a single branch
gh repo clone username/repo -- --single-branch
# Clone with a specific branch
gh repo clone username/repo -- --branch feature-branch --single-branch
# Clone with depth limit
gh repo clone username/repo -- --depth 1
# Clone with sparse checkout
gh repo clone username/repo -- --sparse
Quick Setup Guide
-
Install the completion script:
curl -o ~/.gh-repo-clone-completion.bash https://gist.github.com/chriskyfung/50039cb2a9b586047adc2726085c6280/raw/.bash_profile
You can view the source code on GitHub Gist.
-
Add to your shell:
echo 'source ~/.gh-repo-clone-completion.bash' >> ~/.bashrc # for bash # OR echo 'source ~/.gh-repo-clone-completion.bash' >> ~/.zshrc # for zsh
-
Verify the Setup:
Type
gh repo clone <tab>
in your terminal. If set up correctly, you should see repository suggestions as you type.Type
gh repo clone -- <tab>
in your terminal. You should see additionalgit clone
flags by listing them after--
.
Wrapping Up
Adding this custom completion function can really level up your GitHub CLI game, making it smoother and more user-friendly without the little frustrations. Give it a try and see how much faster your GitHub workflow becomes.
Got questions or suggestions?
Feel free to contribute to the script on GitHub!
Happy coding! 🚀