Skip to content

Bash Script ran in current directory to determine whether the following repo is a work repo or a personal repo

Notifications You must be signed in to change notification settings

amarzbar/GitSwitcher

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 

Repository files navigation

GitSwitcher

This repository contains a script to switch between personal and work git configurations and instructions on setting up SSH for multiple identities.

Git Configuration Script

Usage

This script allows you to set local git credentials for either work or personal use.

Running the Script

To set the git configuration for work, in your local directory corresponding to the git repo you wish to work on type:

./set_git_config.sh --work

To set the git configuration for personal use:

./set_git_config.sh --personal

SSH Configuration

To manage multiple SSH identities (e.g., for GitHub or Gitlab), you need to set up your ~/.ssh/config file.

Generate SSH Keys

Generate separate SSH keys for personal and work use if you haven't already:

# For personal use
ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/.ssh/id_rsa_personal

# For work use
ssh-keygen -t rsa -b 4096 -C "[email protected]" -f ~/.ssh/id_rsa_work

SSH Config File

Create or edit your ~/.ssh/config file with the following content: If you have pre-generated ssh keys you can simply point the IndetityFile attribute to those files instead of the default.

# Personal GitHub account
Host github-personal
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_personal
    IdentitiesOnly yes

# Work GitHub account
Host github-work
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa_work
    IdentitiesOnly yes

Using the Configured Hosts in Git (IMPORTANT)

Update the remote URL for your Git repositories to use the appropriate SSH alias.

For a personal repository:

git remote set-url origin git@github-personal:username/repository.git

Note the change from the typical [email protected]/ to git@github-personal (You can set up whatever name you want but make sure it corresponds with the Host attribute in your .ssh/config file)

Similarly, For a work repository:

git remote set-url origin git@github-work:username/repository.git

About

Bash Script ran in current directory to determine whether the following repo is a work repo or a personal repo

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages