Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Note:</strong> Even though I posted my own solution, I would recommend using <a href="https://github.com/aanand/git-up" rel="noreferrer">git-up</a>, which is also the accepted answer.</p> <hr> <p>I know this question is almost 3 years old, but I asked myself the very same question and did not found any ready made solution. So, I created a custom git command shell script my self.</p> <p>Here it goes, the <code>git-ffwd-update</code> script does the following...</p> <ol> <li>it issues a <code>git remote update</code> to fetch the lates revs </li> <li>then uses <code>git remote show</code> to get a list of local branches that track a remote branch (e.g. branches that can be used with <code>git pull</code>)</li> <li>then it checks with <code>git rev-list --count &lt;REMOTE_BRANCH&gt;..&lt;LOCAL_BRANCH&gt;</code> how many commit the local branch is behind the remote (and ahead vice versa)</li> <li>if the local branch is 1 or more commits ahead, it can <strong>NOT</strong> be fast-forwarded and needs to be merged or rebased by hand</li> <li>if the local branch is 0 commits ahead and 1 or more commits behind, it can be fast-forwarded by <code>git branch -l -f &lt;LOCAL_BRANCH&gt; -t &lt;REMOTE_BRANCH&gt;</code></li> </ol> <p>the script can be called like:</p> <pre><code>$ git ffwd-update Fetching origin branch bigcouch was 10 commit(s) behind of origin/bigcouch. reseting local branch to remote branch develop was 3 commit(s) behind of origin/develop. reseting local branch to remote branch master is 6 commit(s) behind and 1 commit(s) ahead of origin/master. could not be fast-forwarded </code></pre> <p>The full script, should be saved as <code>git-ffwd-update</code> and needs to be on the <code>PATH</code>.</p> <pre class="lang-bash prettyprint-override"><code>#!/bin/bash main() { REMOTES="$@"; if [ -z "$REMOTES" ]; then REMOTES=$(git remote); fi REMOTES=$(echo "$REMOTES" | xargs -n1 echo) CLB=$(git branch -l|awk '/^\*/{print $2}'); echo "$REMOTES" | while read REMOTE; do git remote update $REMOTE git remote show $REMOTE -n \ | awk '/merges with remote/{print $5" "$1}' \ | while read line; do RB=$(echo "$line"|cut -f1 -d" "); ARB="refs/remotes/$REMOTE/$RB"; LB=$(echo "$line"|cut -f2 -d" "); ALB="refs/heads/$LB"; NBEHIND=$(( $(git rev-list --count $ALB..$ARB 2&gt;/dev/null) +0)); NAHEAD=$(( $(git rev-list --count $ARB..$ALB 2&gt;/dev/null) +0)); if [ "$NBEHIND" -gt 0 ]; then if [ "$NAHEAD" -gt 0 ]; then echo " branch $LB is $NBEHIND commit(s) behind and $NAHEAD commit(s) ahead of $REMOTE/$RB. could not be fast-forwarded"; elif [ "$LB" = "$CLB" ]; then echo " branch $LB was $NBEHIND commit(s) behind of $REMOTE/$RB. fast-forward merge"; git merge -q $ARB; else echo " branch $LB was $NBEHIND commit(s) behind of $REMOTE/$RB. reseting local branch to remote"; git branch -l -f $LB -t $ARB &gt;/dev/null; fi fi done done } main $@ </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload