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

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

 



On 12/11/2011 07:22 PM, Jakub Narebski wrote:
> Don't remove people from Cc, please.

OK,

> 
> Gelonida N <gelonida@xxxxxxxxx> writes:
>> On 12/11/2011 03:22 AM, Sitaram Chamarty wrote:

>>
>> 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/ .*$//'


> 
>> 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.

> 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.
>>

> 
> 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.


--
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]