Skip to content

Instantly share code, notes, and snippets.

@wisnia74
Created March 16, 2025 15:13
Show Gist options
  • Select an option

  • Save wisnia74/f51a4fd0261d83964f935e19a19b347b to your computer and use it in GitHub Desktop.

Select an option

Save wisnia74/f51a4fd0261d83964f935e19a19b347b to your computer and use it in GitHub Desktop.
Clone repository using specific ssh identity
#!/bin/bash
# Check if a repository link is provided as an argument
if [ -z "$1" ]; then
echo "Usage: $0 <repository-link>"
exit 1
fi
# Repository link from the argument
REPO_LINK=$1
# Replace "github.com" host with ssh identity you want to use so it uses a proper ssh key as defined in ~/.ssh/config
REPO_LINK_MODIFIED=$(echo "$REPO_LINK" | sed 's/github.com/different-ssh-identity/')
# Capture the repository name from the repo link (after the last slash)
REPO_NAME=$(basename "$REPO_LINK_MODIFIED" .git)
# Clone the repository using the modified link
git clone "$REPO_LINK_MODIFIED"
# Change directory to the project folder
cd "./$REPO_NAME"
# Configure user email and name for the repository
git config user.email "github_user"
git config user.name "github_pass"
# Go back
cd ".."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment