Git - Automatically fast forward all tracking branches on pull

后端 未结 6 1715
闹比i
闹比i 2020-12-28 12:32

I\'ve set up tracking branches with the --track option, and when I do a git pull on master, it fetches all branches to origin/br

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-28 13:24

    Shell script that fast-forwards all branches that have their upstream branch set to the matching origin/ branch without doing any checkouts

    • it doesn't change your current branch at any time, no need to deal with working copy changes and time lost checking out

    • it only does fast-forwards, branches that cannot be fast-forwarded will show an error message and will be skipped

    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;
    

提交回复
热议问题