This tool addresses the challenge of managing multiple Git profiles, such as work and personal, by offering a convenient and efficient means of switching between them.
It's important to note that the process is not atomic, if something fails in the middle of the process, you might end up with a broken configuration. I'm working on a way to make this process more robust.
variant assumes that you have already have git installed and configured. Also the ssh-add command is expected to be available in your PATH, this is what it does.
If you already have cargo installed in your system, use these steps.
cargo install --git https://github.com/muse254/variant.git@mainIt assumes a directory structure that looks like this for the git accounts to be managed, foo and bar:
├── ~/.ssh
│ ├── foo
│ │ ├── config
│ │ ├── id_rsa
│ │ ├── id_rsa.pub
│ ├── bar
│ │ ├── config
│ │ ├── id_rsa
│ │ ├── id_rsa.pubIt's important to note that the name of the folder and the name of the git profile match, in this case foo and bar. When switching profiles, variant will try to pig the
git server to ensure that changes effectively took place.
When I create a new repository, I can specify which account to use:
cd my-awesome-project # We navigate to the project directory
variant var -n foo # We specify which account to use, assuming variant is in PATHThis changes the global git configuration to use the foo account. If you need to only configure an account for the current repository,
you can use the --sacred flag:
cd my-awesome-project
variant var -n foo --sacredThis will tie the project to the specified profile and use local git configuration.
We can also query for information about the profile configured:
variant whoami -vThe project is really a wrapper around git and the ssh commands, so it's not doing anything special. The selling point is ergonomics.
With aliasing magic, I can do this:
alias vf="variant var -n foo"
alias vb="variant var -n bar"
vf # Switch to foo
vb # Switch to barWith some imagination, switching accounts becomes a breeze.