这个脚本应该可以工作:
#!/bin/bash
if [ ! -d .git ]; then
echo "$(basename $0): not a git directory." 1>&2
exit 1
fi
# lbranch - name of local branch
# remote - name of remote
# rbranch - name of remote branch
lbranch=$(git rev-parse --abbrev-ref HEAD)
remote=$(git config branch.${lbranch}.remote)
rbranch=$(git config branch.${lbranch}.merge)
rbranch=${rbranch/refs\/heads\//}
for rev in $(git rev-list --reverse ${lbranch} --not --remotes);
do
git push ${remote} ${rev}:${rbranch}
done
Run Code Online (Sandbox Code Playgroud)