Skip to content

Instantly share code, notes, and snippets.

@tosin2013
Created March 30, 2024 00:10
Show Gist options
  • Save tosin2013/7c3c37efee64d0378a108749a821aa90 to your computer and use it in GitHub Desktop.
Save tosin2013/7c3c37efee64d0378a108749a821aa90 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Check if a repository URL was provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <repository-url>"
exit 1
fi
REPO_URL=$1
# Configure Git to use the credential store
git config --global credential.helper store
# Function to check if we can access the repository
check_access() {
git ls-remote "$REPO_URL" &> /dev/null
}
# Attempt to access the repository
if check_access; then
echo "Access to the repository confirmed."
else
echo "No access or credentials stored for $REPO_URL."
echo "Please enter your credentials. They will be saved for future use."
# Prompt for credentials and perform a git operation to trigger credential storage
git fetch "$REPO_URL"
if [ $? -eq 0 ]; then
echo "Credentials saved and access confirmed."
else
echo "Failed to access the repository with the provided credentials."
exit 1
fi
fi
# Pull from the repository
echo "Pulling from the repository..."
git pull "$REPO_URL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment