Re: best way to fastforward all tracking branches after a fetch

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Gelonida N <gelonida@xxxxxxxxx> wrote:

> What is the best way to fastforward all fastforwardable tracking
> branches after a git fetch?

Here's a script that does this.  It isn't very well tested, I hope I
didn't miss any edge cases. Use at your own risk.

(It doesn't fastforward the branch you're on, on the assumtion that if
you said git fetch instead of git pull, you probably had a reason.)

========= 8< =========
#!/bin/sh

currentbranch="`git symbolic-ref HEAD 2>/dev/null`"

git for-each-ref --shell --format='ref=%(refname);upstream=%(upstream)' \
    refs/heads | \
while read entry
do
    eval "$entry"

    # skip the current branch
    test "$ref" = "$currentbranch" && continue

    # skip branches that have no upstream
    test -z "$upstream" && continue

    # skip if upstream doesn't have any new commits
    if [ -z "`git rev-list "$ref..$upstream"`" ]; then
        echo "${ref#refs/heads/} is up to date"
        continue
    fi

    # error if there are local commits
    if [ -n "`git rev-list "$upstream..$ref"`" ]; then
        echo "${ref#refs/heads/} has local commits; can't fast-forward"
        continue
    fi

    echo "${ref#refs/heads/} -> ${upstream#refs/remotes/}"
    git update-ref -m ff-all-branches "$ref" "$upstream"
done
========= >8 =========


-- 
Stefan Haller
Berlin, Germany
http://www.haller-berlin.de/
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]