Git pull fix

1) Fixes fast forward pull. #1682 

@ussuri 
Not for this PR, but nesting in this function is way too excessive. Consider refactoring.