#!/bin/bash
# 设置源分支和目标分支
source_branch="feature-branch"
target_branch="master"
# 获取当前Git仓库的路径
repo_path=$(git rev-parse --show-toplevel)
# 进入Git仓库目录
cd "$repo_path" || exit
# 获取当前所有分支的列表,并排除source_branch
all_branches=$(git branch -r | grep -v "$source_branch")
# 检查目标分支是否存在
if git show-ref --quiet refs/heads/$target_branch; then
# 目标分支存在,则切换到目标分支
git checkout $target_branch
# 拉取最新的远程分支信息
git pull origin $target_branch
# 合并源分支到目标分支
git merge $source_branch
# 推送合并后的目标分支到远程仓库
git push origin $target_branch
else
echo "Error: Target branch '$target_branch' does not exist."
fi
# 清理:删除本地的源分支
git branch -D $source_branch
评论