If you work with multiple Git users and need an easy way to switch between them, gitswap is the script for you. It allows you to list, add, remove, and switch Git users quickly on Linux, MacOS, and Windows.
-
Clone the Repository:
- Clone the gitswap repository to your local machine using the following command:
git clone https://github.com/vinugawade/gitswap.git
-
Move the Script to a Global Location:
- Move the script to a global location on your system using the following command:
sudo mv /location/of/gitswap /usr/local/bin
-
Set Script Permissions:
- Allow everyone to execute the script by choosing one of the following commands:
sudo chmod +x /location/of/gitswap
OR
sudo chmod 0755 /location/of/gitswap
-
Add to $PATH:
- Add
/usr/local/binto your$PATH. If you use the Bash shell, execute the command:
export PATH=$PATH:/usr/local/bin
OR
export PATH=$PATH:/location/of/gitswap
This will set the variable name, potentially in a file like
~/.bash_profile,~/.bashrc, or~/.profile. If you're unsure where to put it,~/.bashrcis a good choice. - Add
You may need to restart your shell for this to take effect.
The gitswap script supports the following options:
--switch, -s: Switch to a new or existing Git user.--add, -a: Add a new Git user to the list.--remove, -r: Remove a Git user from the list.--show, -sh: Display the current Git user configuration.
-
Switch User: Switch to an existing Git user or add a new one if the user doesn't exist.
gitswap "John Doe" "john.doe@example.com"
-
Add User: Add a new Git user to the saved list.
gitswap --add # Prompts to add a new Git user to the list gitswap "Jane Doe" "jane.doe@example.com" # Adds a new user if provided
-
Remove User: Remove a Git user from the saved list.
gitswap --remove # Prompts to choose a user to remove -
Show Current User: Display the current Git user configuration.
gitswap --show # Displays the current Git user configuration -
List Users: If no arguments or options are provided,
gitswapwill list all saved Git users.gitswap # Lists all saved Git users
- Switch Users: Easily switch between multiple Git users.
- Add Users: Add new Git users to the saved list.
- Remove Users: Remove users from the saved list.
- Show Current User: Quickly view the currently active Git user.
- Auto-Add: If no users are saved, the current Git user is automatically added to the list.
Built With 💙✨ By Vinay Gawade.
This project is licensed under the LICENSE file associated with this repository.