Struggling with managing SSH aliases for multiple Git projects on the same server? SGH is here to simplify your life.
SGH (Server Git Helper) is a utility script engineered to automate the cumbersome task of juggling multiple SSH keys across various Git repositories. This guide offers a step-by-step walkthrough for initial setup and subsequent usage.
You can use curl or wget to download sgh.sh directly to your server's home directory. Here's how:
Using curl:
curl -o ~/sgh https://raw.githubusercontent.com/RocketFry/server-git-helper/main/sgh.shOr using wget:
wget -O ~/sgh https://raw.githubusercontent.com/RocketFry/server-git-helper/main/sgh.shThen, make the script executable:
chmod +x ~/sghIf you prefer not to use curl or wget, you can manually copy the content as described in the original guide.
Here are some example commands to help you get started:
~/sgh create --alias [alias-name] --repo [repo-url]Example:
~/sgh create --alias sgh-example --repo git@github.com:RocketFry/server-git-helper.git~/sgh publickey --alias sgh-exampleNote: After creating a new alias, you'll need to add its publickey as a deploy key within your GitHub or GitLab project settings.
~/sgh clone --alias sgh-example --dir ./server-git-helper-example~/sgh pull --alias sgh-example --branch main --remote originNote: The --branch and --remote options are optional. If not specified, main will be used for the branch and origin for the remote.
~/sgh list~/sgh delete --alias sgh-example~/sgh clean --alias sgh-example~/sgh exec --alias [alias-name] [raw git commands]Usage Examples:
To fetch updates for an alias named sgh-example:
~/sgh exec --alias sgh-example fetchImportant Notes:
- Power & Responsibility: The
execcommand is powerful and flexible. However, it comes with the responsibility of knowing what each Git command will do, assgh execdoes not have built-in safeguards against potentially destructive actions.
To update, follow the same initial steps you used for installation. Typically, you can update sgh using curl, wget, or by manually copying the script again.
Example using curl:
curl -o ~/sgh https://raw.githubusercontent.com/RocketFry/server-git-helper/main/sgh.shExample using wget:
wget -O ~/sgh https://raw.githubusercontent.com/RocketFry/server-git-helper/main/sgh.shAnd there you have it! You've now successfully set up SGH and can streamline your SSH key management across multiple Git repositories.