From da2260d414963dc724203be2d4dd2a9d887a8052 Mon Sep 17 00:00:00 2001 From: Ali Date: Thu, 18 Dec 2025 10:00:05 +0800 Subject: [PATCH] Added gpull. --- gpull | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100755 gpull diff --git a/gpull b/gpull new file mode 100755 index 0000000..ad546d2 --- /dev/null +++ b/gpull @@ -0,0 +1,54 @@ +#!/bin/bash +# --------------------------------------------------------------------------- +# gpull – Pull changes from a remote Git repository +# +# Usage: +# ./gpull [repo] [remote] [branch] +# +# repo – (optional) Directory of repository to pull, default is current directory. +# remote – (optional) Remote name, default is origin. +# branch – (optional) Branch name, default is current branch. +# +# The script will pull the specific remote branch into the local repository. +# --------------------------------------------------------------------------- + +# Get command line arguments +repo_dir=${1:-$(pwd)} +remote=${2:-origin} +branch=${3:-} + +# Change to the specified directory +if [ ! -d "$repo_dir" ]; then + echo "Error: Directory '$repo_dir' does not exist." + exit 1 +fi + +cd "$repo_dir" || exit 1 + +# Check if the current directory is a git repository +if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then + echo "Error: '$repo_dir' is not a git repository." + exit 1 +fi + +# If no branch specified, get the current branch +if [ -z "$branch" ]; then + branch=$(git rev-parse --abbrev-ref HEAD) + if [ "$branch" = "HEAD" ]; then + echo "Error: Not currently on a branch. Please specify a branch to pull." + exit 1 + fi +fi + +echo "Pulling changes from $remote/$branch into $repo_dir" + +# Perform the git pull +git pull "$remote" "$branch" + +# Check if the pull was successful +if [ $? -eq 0 ]; then + echo "Successfully pulled changes from $remote/$branch" +else + echo "Error: Failed to pull changes from $remote/$branch" + exit 1 +fi