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

前端 未结 25 2463
失恋的感觉
失恋的感觉 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:16

    A slightly different script that only fast-forwards branches who's names matches their upstream branch. It also updates the current branch if fast-forward is possible.

    Make sure all your branches' upstream branches are set correctly by running git branch -vv. Set the upstream branch with git branch -u origin/yourbanchname

    Copy-paste into a file and chmod 755:

    #!/bin/sh
    
    curbranch=$(git rev-parse --abbrev-ref HEAD)
    
    for branch in $(git for-each-ref refs/heads --format="%(refname:short)"); do
            upbranch=$(git config --get branch.$branch.merge | sed 's:refs/heads/::');
            if [ "$branch" = "$upbranch" ]; then
                    if [ "$branch" = "$curbranch" ]; then
                            echo Fast forwarding current branch $curbranch
                            git merge --ff-only origin/$upbranch
                    else
                            echo Fast forwarding $branch with origin/$upbranch
                            git fetch . origin/$upbranch:$branch
                    fi
            fi
    done;
    

提交回复
热议问题