gcbo (short for git clone branch only) is a small CLI tool to selectively clone a single branch from a git repository. I wanted it to be standalone and vanilla (ie not require any pip install xyz
or so, even though simple-term-menu is super nice). The name was chosen as it kinda resembles zsh shortcuts (such as dco
for docker-compose
)
So actually this is just a lot of boiler plate around
git clone, -b, ${BRANCH}, --single-branch, ${REPO}, ${TARGET_DIR}
but it comes in handy as you don't have to remember how the branch was called, which I never do in particular as things like Jira decide on the full name of the branch and you'd have to update refs and search them first. To make matters even worse some (or at least I) have dozens of repos at github, gitlab, bitbucket, some private VCS instance and nearly as many ssh keys to use. I simply cannot be bothered to remember URLs, keypaths and the like.
I am a big proponent of reviewing PRs on a clean slate. For small projects just changing the branch (as in git checkout feature_123
) works well, but larger projects often have multiple configs and/or some files not in VCS (think access key, .env files). Just changing to the branch to review and running (int) test might fail due to changes you overlooked or configs that are outdated or unexpectedly present. Even worse, the test may pass on the local machine but fail in CI 🙀 (or even worse, production 🙀 🙀 🙀).
Just save the main file somewhere handy (~/bin/gcbo
comes to mind) and save the sample config as ~/.gcbo.json
be sure to mind the dot. Then you either chmod u+x /path/to/gcbo
and run it, or call it as python3 /path/to/gcbo
. The sample sets up to public git repos for you to try.
In case you're trusting me2 you can also just paste this in your Terminal.
curl https://raw.githubusercontent.com/stefanSchinkel/gcbo/master/gcbo -o ~/bin/gcbo
curl https://raw.githubusercontent.com/stefanSchinkel/gcbo/master/.gcbo.json.sample -o ~/.gcbo.json
chmod u+x ~/bin/gcbo
Next to none:
- python3.6+2 on a *nix system
- git
Only one to keep track of the repos locate in ${HOME}/.gcbo.json
. See the sample file that is rather self-explanatory (keys are ignored for now.)
Things that need to be done, not necessarily in order
- repo per arg
- save repo passed per arg
- add repo when no config and none given as arg
- sighandler for Ctrl+c
- "Go back" in menus
- honour ssh key
- pass ssh key via -i option
1: But maybe you shouldn't trust stangers on the internet. 2: If you ask nicely, I might drop f-strings to support older python 3 versions too.