Created
March 30, 2024 00:10
-
-
Save tosin2013/7c3c37efee64d0378a108749a821aa90 to your computer and use it in GitHub Desktop.
./git-credential-store.sh https://github.com/username/repository.git https://git-scm.com/docs/git-credential-store
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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