常见问题
解决本地分支和远程历史分叉问题
发给 ChatGPT / Claude 等 AI,可更快消化本页并上手上站。
Created: 10/17/2026
Updated: 10/18/2026
如果你本地分支都和远程历史分叉了,执行下面命令可和远程对齐
git fetch origin --prune
current=$(git branch --show-current)
git for-each-ref --format='%(refname:short) %(upstream:short)' refs/heads | while read b up; do
[ -z "$up" ] && continue
if [ "$b" = "$current" ]; then
git reset --hard "$up"
else
git branch -f "$b" "$up"
fi
done