git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Sitaram Chamarty <sitaramc@gmail.com>
Date
Dec 17, 2011, 10:10 UTC
Message-ID
<20111217101009.GA19248@sita-lt.atc.tcs.com>
In-Reply-To
<jbvj5o$skt$1@dough.gmane.org>
On Sat, Dec 10, 2011 at 01:26:32PM +0100, Gelonida N wrote:
> Hi,
> 
> What is the best way to fastforward all fastforwardable tracking
> branches after a git fetch?

I know this is a somewhat closed topic, but I took some time to clean up a program I have been using for a while, including some changes based upon ideas elsewhere in this thread. The program "git-branch-check" is attached, and requires perl > 5.10.0.

Note that this does a lot more than just fast-forward all branches, although it can do that as well.

I alias it (in ~/.gitconfig) to 'bc', so I just run "git bc". Running with "-h" shows usage:

    Usage: /home/sitaram/bin/git-branch-check [options] [branches]
    Check or fast forward branches.  Default: act upon all local branches if no
    arguments supplied, or just the current branch if '-c' is passed.
            -c      act upon current branch only
            -ff     don't just check, try to fast forward also
            -md     max diff (default 100; see below for details)
            -h      help
    'max diff':
        hide output for two branches different by more than so many commits
My usual usage is just "git bc -c", which may give me:
       1        pu...origin/pu
       1        pu...github/pu
      13        pu...master
           5    pu...q
           7    pu...vrs

This quickly tells me my 'pu' is one ahead of both my own gitolite server as well as github's copy, and that it is 13 commits ahead of master. The (unreleased and frequently rebased) feature branches 'q' and 'vrs' are ahead of pu, which means a rebase is not pending. Without the "-c" I may see the status of master versus its own upstream and other remotes, etc., also.

The purpose of the max diff limit (default 100) is to hide, for example, the pair 'master' and 'man' from the git.git repo. Otherwise you'd see something like:

    27249 973    master...man

which is pretty meaningless. The sum of those two numbers should be less than the max.

"git bc -ff" will attempt to fast forward all selected branches that are ancestors of their respective upstreams. The current branch will not be ff-ed if the tree is dirty, since you can't do this by 'git branch -f'; it has to be an actual merge command.

The output is not (currently) pipable to other programs because I use colors (obtained from 'git config --get-color') and currently it is not conditional on STDOUT being a tty.

Previous: Gelonida NNext: Sitaram Chamarty
Message 23 of 27 in “best way to fastforward all tracking branches after a fetch”
  1. Gelonida NDec 10, 2011
  2. Sitaram ChamartyDec 11, 2011
  3. Gelonida NDec 11, 2011
  4. Jakub NarebskiDec 11, 2011
  5. Sitaram ChamartyDec 11, 2011
  6. Andreas SchwabDec 11, 2011
  7. Jakub NarebskiDec 11, 2011
  8. Gelonida NDec 11, 2011
  9. Andreas SchwabDec 11, 2011
  10. Martin LanghoffDec 11, 2011
  11. Stefan HallerDec 11, 2011
  12. Gelonida NDec 11, 2011
  13. Martin LanghoffDec 11, 2011
  14. Hallvard B FurusethDec 11, 2011
  15. Stefan HallerDec 12, 2011
  16. Jeff KingDec 12, 2011
  17. Stefan HallerDec 12, 2011
  18. Hallvard Breien FurusethDec 13, 2011
  19. Junio C HamanoDec 12, 2011
  20. Junio C HamanoDec 12, 2011
  21. Gelonida NDec 12, 2011
  22. Gelonida NDec 12, 2011
  23. Sitaram ChamartyDec 17, 2011
  24. Sitaram ChamartyDec 17, 2011
  25. Nazri RamliyDec 19, 2011
  26. Sitaram ChamartyJan 18, 2012
  27. Sitaram ChamartyJan 18, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.