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
GNGelonida N <gelonida@gmail.com>
Date
Dec 11, 2011, 19:58 UTC
Message-ID
<4EE50B5A.3000706@gmail.com>
In-Reply-To
<m3ehwbge8f.fsf@localhost.localdomain>
On 12/11/2011 07:22 PM, Jakub Narebski wrote:
> Don't remove people from Cc, please.
OK,
> 
> Gelonida N <gelonida@gmail.com> writes:
>> On 12/11/2011 03:22 AM, Sitaram Chamarty wrote:
Show 10 quoted lines
>>
>> In order to save time I'd like to avoid checking out local branches.
> 
> You can use 'upstream' field name in git-for-each-ref invocation,
> for example
> 
>   git for-each-ref '--format=%(refname:short) %(upstream:short)' refs/heads |
>   	grep -e ' [^ ]' |
>   	sed  -e 's/ .*$//
>  
Thanks
> This could probably be done using only sed -- grep is not necessary.

I think the equivalent would be: sed '/ [^ ]/ s/ .*$//'

Show 8 quoted lines
> 
>> Ideally I would even like to avoid checking out branches, which don't
>> need to be forwarded.
>  
> You can use git-update-ref plumbing, but you would have to do the
> check if it does fast-forward yourself, and provide reflog message
> yourself too.
>  

True this would probably be fastest. Will read the docs a little to understand exactly what you're doing. I'm not that much used to all the commands used in the script.

Show 15 quoted lines
> Something like
> 
>   git for-each-ref '--format=%(refname) %(upstream)' |
>   while read refname upstream
>   do
>   	# there is upstream
>   	test -n "$upstream" || break
>   	# and if fast-forwards
>   	test $(git merge-base $refname $upstream) = $(git rev-parse $refname) || break
>   	git update-ref -m "$message" $refname $upstream
>   done
> 
>> I also had to remember on which branch I was in order to avoid, that I
>> am at a random branch after running the script.
>>
Show 11 quoted lines
> 
> Don't use git-branch in scripting.  See __git_ps1 function in
> contrib/completion/git-completion.bash how it can be done:
> 
>   b="$(git symbolic-ref HEAD 2>/dev/null)" ||
>   b="$(git rev-parse --verify HEAD)"
> 
> Nb. the second part is here only if there is possibility that you are
> on detached HEAD (unnamed branch).
> 
> HTH (hope that helps)

It definitely helps. Thanks a lot. It's always good to see how one can do better after some attempts o some self made clumsy scripts not suing all the features of git.

Previous: Jakub NarebskiNext: Andreas Schwab
Message 8 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.