Can “git pull --all” update all my local branches?

前端 未结 25 2162
失恋的感觉
失恋的感觉 2020-11-22 16:33

I often have at least 3 remote branches: master, staging and production. I have 3 local branches that track those remote branches.

Updating all my local branches is

25条回答
  •  名媛妹妹
    2020-11-22 17:14

    It can be done using below script... It will first fetch all branches and checkout one by one and update by itself.

    #!/bin/bash
    git branch -r | grep -v '\->' | while read remote; do git branch --track 
    "${remote#origin/}" "$remote"; done
    
    set -x
    CURRENT=`git rev-parse --abbrev-ref HEAD`
    git fetch --all
    branch_name=$(git branch | awk '{print $1" "}' | grep -v '*' | xargs)
    for branch in $branch_name; do
       git checkout "$branch" || exit 1
       git rebase "origin/$branch" || exit 1
       git pull origin $branch|| exit 1
    done
    git checkout "$CURRENT" || exit 1
    git pull || exit 1
    

提交回复
热议问题