!/bin/bash
shell script delete remote branch and local branch
if [[ "" == 2 ]]; then
echo "please add reponsitory path and delete date"
echo "example: ./delete_mr.sh ./npu-codebase 365 ###删除超过365天时间的分支"
exit
fi
reponsitory_name="reponsitory_name"】 branchs !!!!!!";
echo " "
cd 2"
for branch in git branch -r --no-merged | grep -v HEAD
;
do
分支名称
branch_name=echo $branch | grep '/' | cut -d '/' -f 2-
;
分支最后提交时间
branch_timestamp=git show --format="%ct" $branch | head -n 1
;
当前系统时间
cur_sec_and_ns=date '+%s-%N'
;
cur_sec=${cur_sec_and_ns%-*};
时间差
time_different=branch_timestamp];
阈值g
time_require=days];
if [[ "" != "$branch_name"
&& "HEAD" != "$branch_name"
&& "master" != "$branch_name"
&& $time_different -ge $time_require
]]; then
echo "deleting current branch: " `git show --format="%ci %cr" $branch | head -n 1` $branch_name
echo "branch_name: " $branch_name
echo "delete local "$branch_name
local_result=`git branch -d $branch_name`
echo "delete remote "$branch_name
remote_result=`git push origin --delete $branch_name`
echo "delete over"
echo ""
fi
done
echo "!!!!! game over !!!!!";