Scripts/git_commit
2025-06-10 02:00:12 +00:00

48 lines
1.2 KiB
Bash

#!/bin/bash
# bash <(curl -s https://git.technozone.com.au/vijay/Scripts/raw/branch/main/git_commit) && rm -f git_commit
# Prompt for the Gitea repository URL
read -p "Enter your Gitea repository URL: " GITEA_URL
# Function to prompt for the access token
prompt_for_token() {
read -sp "Enter your Gitea access token: " GIT_TOKEN
echo
}
# Check for existing Git token
if [ -z "$GIT_TOKEN" ]; then
echo "No Git token found."
prompt_for_token
else
echo "Using existing Git token."
fi
# Fetch the list of remote repositories
echo "Fetching remote repositories..."
git remote -v
# Check for changes in the remote repository
echo "Checking for changes in the remote repository..."
git fetch
# Check if there are any changes to pull
if [ $(git rev-list --count HEAD..origin/main) -gt 0 ]; then
echo "Changes found in the remote repository. Pulling changes..."
git pull origin main
fi
# Stage changes
echo "Staging changes..."
git add .
# Commit changes
read -p "Enter your commit message: " commit_message
git commit -m "$commit_message"
# Push changes using the access token
echo "Pushing changes using access token..."
git push "https://$GIT_TOKEN@${GITEA_URL#https://}"
echo "Changes pushed successfully."