A nifty shell function to clone GitHub repositories using gh
instead of git clone
, complete with authentication support from the second account, for those pesky rate-limited accounts. 🛠️
Tired of git clone
breaking your heart (and your code) with its fickle ways? 😩 GH-Clone-Helper is your new reliable BFF. It's like a warm hug for your repositories, ensuring a smooth cloning process even when your internet decides to play hard to get. 🌐💔.
More mundanely: Many end-users encounter issues with the standard git clone
where the cloning process breaks, especially when dealing with large repositories or unstable Internet connections. Common fixes such as increasing http.postBuffer
or using shallow clones often do not resolve these issues. The git clone
command can fail due to various reasons, including network timeouts and data transfer interruptions, leading to incomplete clones that cannot be resumed from the point of failure.
GH-Clone-Helper
(now at: https://github.com/Manamama/GH-Clone-Helper/blob/main/gh_clone_with_token.sh) aims to provide a more robust solution by leveraging the GitHub CLI, its gh clone
, which uses GitHub's API for cloning operations, offering a more stable and reliable cloning process.
To kick things off with GH-Clone-Helper, you'll need a personal access token (PAT) from your sidekick GitHub account. This little golden key 🗝️ will let GH-Clone-Helper step in on your behalf, especially handy when your main account is taking a timeout. 🕒
- Sneak into your secondary GitHub account. 🕵️♂️
- Navigate to your account settings.
- Hit "Developer settings" like it owes you money. 💰
- Choose "Personal access tokens" and treat yourself to a "Generate new token" moment.
- Name your token something memorable, pick the powers you want to bestow upon it (minimum:
repo
), and let the magic happen. ✨ - Heads up: Copy your token now! It's a shy one and won't show itself again. 🙈
- Pop open a terminal window.
- Summon a text editor and conjure up a
.ghtoken2
file in your home directory:nano ~/.ghtoken2
- Make sure the GitHub CLI is part of your toolkit and on speaking terms with your secondary token.
- Cozy up your shell configuration file with the
gh_clone_with_token
function. It's like inviting a friend over. 🏡 - Give your terminal a quick refresh or just reboot. It's like a spa day for your CLI. 🧖♂️
When you're ready to bring a new repo into your life, just whisper sweet nothings to the function like so:
gh_clone_with_token "https://github.com/username/repository.git"
And voilà! The script will work its magic, leaving you with a perfectly cloned repo. 🎩✨
PS. Sending a high-five to Microsoft Copilot🤖🦜🦉 (still in the Creative mode) for the assist on this script! 🙌 And remember, keep your tokens close and your repositories closer. 😉🔒 (And MS Copilot wrote most of the above, too.)
⬛⬜⬛⬜⬛
⬜⬛⬜⬛⬜
⬛⬜⬛⬜⬛
ver. 1.0.2