diff --git a/packages/flutter_tools/lib/src/commands/channel.dart b/packages/flutter_tools/lib/src/commands/channel.dart index 0b5599e12c..d47381ea95 100644 --- a/packages/flutter_tools/lib/src/commands/channel.dart +++ b/packages/flutter_tools/lib/src/commands/channel.dart @@ -92,25 +92,34 @@ class ChannelCommand extends FlutterCommand { } static Future _checkout(String branchName) async { + // Get latest refs from upstream. int result = await runCommandAndStreamOutput( - ['git', 'show-ref', '--verify', '--quiet', 'refs/heads/$branchName'], + ['git', 'fetch'], workingDirectory: Cache.flutterRoot, prefix: 'git: ', ); + if (result == 0) { - // branch already exists, try just switching to it result = await runCommandAndStreamOutput( - ['git', 'checkout', branchName], - workingDirectory: Cache.flutterRoot, - prefix: 'git: ', - ); - } else { - // branch does not exist, we have to create it - result = await runCommandAndStreamOutput( - ['git', 'checkout', '--track', '-b', branchName, 'origin/$branchName'], + ['git', 'show-ref', '--verify', '--quiet', 'refs/heads/$branchName'], workingDirectory: Cache.flutterRoot, prefix: 'git: ', ); + if (result == 0) { + // branch already exists, try just switching to it + result = await runCommandAndStreamOutput( + ['git', 'checkout', branchName], + workingDirectory: Cache.flutterRoot, + prefix: 'git: ', + ); + } else { + // branch does not exist, we have to create it + result = await runCommandAndStreamOutput( + ['git', 'checkout', '--track', '-b', branchName, 'origin/$branchName'], + workingDirectory: Cache.flutterRoot, + prefix: 'git: ', + ); + } } if (result != 0) throwToolExit('Switching channels failed with error code $result.', exitCode: result);