Add git_commit
This commit is contained in:
parent
9b469c36cf
commit
a183effc9f
53
git_commit
Normal file
53
git_commit
Normal file
@ -0,0 +1,53 @@
|
||||
#!/bin/bash
|
||||
# Run this script from a Git repository: ./git_push.sh
|
||||
|
||||
# Prompt for the Gitea repository URL
|
||||
read -p "Enter your Gitea repository URL: " GITEA_URL
|
||||
|
||||
# Function to prompt for username and password
|
||||
prompt_for_credentials() {
|
||||
read -p "Enter your Gitea username: " username
|
||||
read -sp "Enter your Gitea password: " password
|
||||
echo
|
||||
}
|
||||
|
||||
# Check for existing Git credentials (token)
|
||||
if [ -z "$GIT_TOKEN" ]; then
|
||||
echo "No Git token found."
|
||||
prompt_for_credentials
|
||||
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
|
||||
if [ -z "$GIT_TOKEN" ]; then
|
||||
echo "Pushing changes using username and password..."
|
||||
git push "$GITEA_URL" --username "$username" --password "$password"
|
||||
else
|
||||
echo "Pushing changes using token..."
|
||||
git push "$GITEA_URL"
|
||||
fi
|
||||
|
||||
echo "Changes pushed successfully."
|
||||
Loading…
x
Reference in New Issue
Block a user