Crates.io | git-switch |
lib.rs | git-switch |
version | 0.0.7 |
source | src |
created_at | 2023-07-13 12:16:32.736368 |
updated_at | 2024-06-06 12:31:56.087511 |
description | A tool to switch between git user configs |
homepage | https://github.com/ashikmeerankutty/git-switch |
repository | https://github.com/ashikmeerankutty/git-switch |
max_upload_size | |
id | 915260 |
size | 13,725 |
Switch between Git user configs
cargo install git-switch
To install git-switch
, use the above command. This assumes you have Rust and Cargo installed on your system.
touch ~/.git-switch.json
This will create a file named .git-switch.json
in your home directory (~
).
.git-switch.json
file in a text editor and add the desired Git configurations. The file should be in JSON format and contain an array of objects. Each object represents a Git host (e.g., GitHub, GitLab) and includes the following properties:
"host"
: The hostname of the Git service."username"
: The desired username."email"
: The desired email address.Here's an example configuration file:
[
{
"host": "github.com",
"username": "ashikmeerankutty",
"email": "ashik9591@gmail.com"
},
{
"host": "gitlab.com",
"username": "ameerankutty",
"email": "ameerankutty@gitlab.com"
}
]
Feel free to add or remove configurations based on your needs.
git-switch
This will read the .git-switch.json
file from your home directory and update the Git configurations based on the current directory.
To automatically change the Git config when the directory changes, follow these steps:
code ~/.zshrc
Replace code
with the command for your preferred text editor.
~/.zshrc
file:# Run git-switch on directory change
git_switch_on_chpwd() {
git-switch
}
# Set up chpwd hook
add-zsh-hook chpwd git_switch_on_chpwd
This code sets up a chpwd
hook, which is executed whenever the current directory changes. It calls git-switch
to update the Git configurations accordingly.
source ~/.zshrc
Now, whenever you change directories in your terminal, the git-switch
command will automatically be executed to update the Git configurations based on the current directory.