@@ -259,30 +259,38 @@ static int update_head_to_remote(
259259
260260static int update_head_to_branch (
261261 git_repository * repo ,
262- const char * remote_name ,
262+ git_remote * remote ,
263263 const char * branch ,
264264 const char * reflog_message )
265265{
266266 int retcode ;
267267 git_buf remote_branch_name = GIT_BUF_INIT ;
268268 git_reference * remote_ref = NULL ;
269+ git_buf default_branch = GIT_BUF_INIT ;
269270
270- GIT_ASSERT_ARG (remote_name );
271+ GIT_ASSERT_ARG (remote );
271272 GIT_ASSERT_ARG (branch );
272273
273274 if ((retcode = git_buf_printf (& remote_branch_name , GIT_REFS_REMOTES_DIR "%s/%s" ,
274- remote_name , branch )) < 0 )
275+ git_remote_name ( remote ) , branch )) < 0 )
275276 goto cleanup ;
276277
277278 if ((retcode = git_reference_lookup (& remote_ref , repo , git_buf_cstr (& remote_branch_name ))) < 0 )
278279 goto cleanup ;
279280
280- retcode = update_head_to_new_branch (repo , git_reference_target (remote_ref ), branch ,
281- reflog_message );
281+ if ((retcode = update_head_to_new_branch (repo , git_reference_target (remote_ref ), branch ,
282+ reflog_message )) < 0 )
283+ goto cleanup ;
284+
285+ if ((retcode = git_remote_default_branch (& default_branch , remote )) < 0 )
286+ goto cleanup ;
287+
288+ retcode = update_remote_head (repo , remote , & default_branch , reflog_message );
282289
283290cleanup :
284291 git_reference_free (remote_ref );
285292 git_buf_dispose (& remote_branch_name );
293+ git_buf_dispose (& default_branch );
286294 return retcode ;
287295}
288296
@@ -367,8 +375,7 @@ static int checkout_branch(git_repository *repo, git_remote *remote, const git_c
367375 int error ;
368376
369377 if (branch )
370- error = update_head_to_branch (repo , git_remote_name (remote ), branch ,
371- reflog_message );
378+ error = update_head_to_branch (repo , remote , branch , reflog_message );
372379 /* Point HEAD to the same ref as the remote's head */
373380 else
374381 error = update_head_to_remote (repo , remote , reflog_message );
0 commit comments