Added gpush.
This commit is contained in:
96
gpush
Executable file
96
gpush
Executable file
@@ -0,0 +1,96 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Usage notes for gpush script
|
||||
#
|
||||
# This script automates the process of committing and pushing changes to a git repository.
|
||||
# It also supports creating and pushing tags.
|
||||
#
|
||||
# Features:
|
||||
# - Automatically detects if you're in a git repository
|
||||
# - Shows current repository info (URL, tag, branch)
|
||||
# - Allows custom commit messages
|
||||
# - Supports custom remote and branch targets
|
||||
# - Option to create and push tags
|
||||
#
|
||||
# Usage:
|
||||
# ./gpush [default_commit_message]
|
||||
#
|
||||
# Examples:
|
||||
# ./gpush # Run with no default commit message
|
||||
# ./gpush "Fixed bug in login flow" # Run with a default commit message
|
||||
#
|
||||
# The script will prompt for:
|
||||
# - Commit message (uses default if provided, can be changed)
|
||||
# - Remote name (defaults to 'origin')
|
||||
# - Branch name (defaults to current branch)
|
||||
# - Tag name (optional, no tag created if left blank)
|
||||
#
|
||||
# After confirming the actions, it will:
|
||||
# 1. Add all changes (git add .)
|
||||
# 2. Commit with your message (git commit -am "message")
|
||||
# 3. Push to your specified remote/branch (git push remote branch)
|
||||
# 4. Create and push tag if specified
|
||||
|
||||
# Check if the current directory is a git repository
|
||||
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
|
||||
echo "Error: Not a git repository."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Gather info
|
||||
# Note: not capturing git log message because of colour loss.
|
||||
repo=$(git remote get-url origin)
|
||||
currTag=$(git describe --tags)
|
||||
currBranch=$(git rev-parse --abbrev-ref HEAD) # $(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
|
||||
inputCommit=$1
|
||||
if [ -z $currBranch ]
|
||||
then
|
||||
currBranch='master'
|
||||
fi
|
||||
|
||||
echo "Commit Changes and Push to Git Repository"
|
||||
echo "--------------------------------------------------------------------------------"
|
||||
git log -1
|
||||
echo ""
|
||||
echo "Repository : $repo"
|
||||
echo "Current Tag: $currTag"
|
||||
echo "--------------------------------------------------------------------------------"
|
||||
echo "Commands will be executed in batch at the after confirmation."
|
||||
echo "Press Ctrl-C at any point to cancel all actions."
|
||||
echo ""
|
||||
read -p "Input commit message (default: $inputCommit): " commit
|
||||
read -p "Input remote (default: origin): " remote
|
||||
read -p "Input branch (current: $currBranch): " branch
|
||||
read -p "Input tag (default: no tag): " tag
|
||||
remote=${remote:-origin}
|
||||
branch=${branch:-$currBranch}
|
||||
commit=${commit:-$inputCommit}
|
||||
echo "--------------------------------------------------------------------------------"
|
||||
echo "Prepared command(s):"
|
||||
echo ""
|
||||
if [ "$commit" ]
|
||||
then
|
||||
echo " git add .";
|
||||
echo " git commit -am \"$commit\""
|
||||
fi
|
||||
echo " git push $remote $branch";
|
||||
if [ "$tag" ]
|
||||
then
|
||||
echo " git tag \"$tag\""
|
||||
echo " git push $remote --tags"
|
||||
fi
|
||||
echo ""
|
||||
echo "Enter to execute:"
|
||||
read confirm
|
||||
echo "--------------------------------------------------------------------------------"
|
||||
if [ "$commit" ]
|
||||
then
|
||||
git add .
|
||||
git commit -am "$commit"
|
||||
git push "$remote" "$branch"
|
||||
if [ "$tag" ]; then
|
||||
git tag "$tag"
|
||||
git push "$remote" "$tag"
|
||||
fi
|
||||
#git push $remote $branch --tags
|
||||
fi
|
||||
Reference in New Issue
Block a user