Managing large amounts of VCS repos locally
How to organize local git clones
- Where to put your local git repos so that they are easy to find?
- How do you avoid name clashes maybe two repos have the same name, or you have a clone of the upstream repo and your fork (same name)
Solution: mirror the git URL locally + shell bookmark manager
Repo cloning
By mirroring the URL locally it’s easy to know where to find a repo e.g. https://github.com/someuser/somerepo will be locally at
I use the excellent tool ghq ($ brew install ghq
) to clone my repos as it automatically clones the repos to a base dir following the above URL pattern!
(my clone base is ~/src
)
$ pwd
~/
$ ghq get --look git@github.com:someuser/somerepo.git
$ # make ^ a shell alias like 'clone' or something
$ pwd
~/src/github.com/someuser/somerepo
This is how my clone base looks
$ tree -d -L 3 ~/src
/Users/erikw/src
├── aur.archlinux.org
│ ├── restic-automatic-backup-scheduler
│ ├── snp
│ └── zscreen
├── bitbucket.org
│ └── taschik
│ ├── flight-buddy-frontend
│ └── flight-buddy-server
├── github.com
│ ├── KenKundert
│ │ ├── nestedtext
│ ├── Rapptz
│ │ └── discord.py
│ ├── erikw
│ │ ├── advent-of-code-solutions
│ │ ├── dotfiles
│ │ ├── erikw.github.io
│ │ ├── escape-from-dev-null
│ │ ├── ewxb-gcc-cross-compiler-builder
│ │ ├── exsportify
│ │ ├── hackerrank-solutions
│ │ ├── nestedtext
│ │ └── ...
Navigating locally
So yes the clone paths are now a bit longer that is true. Once you’re in your base dir for working like ~/src/github.com/erikw all good though.
What I can really recommend is getting a bookmark manager for your shell. Then it’s a breeze to go to the above base or specific repo
This is how it works in my shell
$ cd ~/src/github.com/erikw/dotfiles
$ s dot # save bookmark as dot
$ cd /somewhere/else
$ g dot # jump to my bookmark
$ pwd
$ ~/src/github.com/erikw/dotfiles
I use fzf-marks (s and g being shell aliases to the fzf-mark commands) currently as I’m really in to the whole fzf fuzzy search toolchain.
Otherwise I maintain a fork of cd-bookmark that works for zsh and bash, also works great!
Leave a comment
Your email address will not be published. Required fields are marked *