Skip to content

Commit b926648

Browse files
author
Edward Thomson
committed
documentation: improve docs for checkout_head
`git_checkout_head` is sadly misunderstood as something that can switch branches. It cannot. Update the documentation to reflect this.
1 parent 2a09de9 commit b926648

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

include/git2/checkout.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,13 @@ GIT_EXTERN(int) git_checkout_init_options(
313313
* Updates files in the index and the working tree to match the content of
314314
* the commit pointed at by HEAD.
315315
*
316+
* Note that this is _not_ the correct mechanism used to switch branches;
317+
* do not change your `HEAD` and then call this method, that would leave
318+
* you with checkout conflicts since your working directory would then
319+
* appear to be dirty. Instead, checkout the target of the branch and
320+
* then update `HEAD` using `git_repository_set_head` to point to the
321+
* branch you checked out.
322+
*
316323
* @param repo repository to check out (must be non-bare)
317324
* @param opts specifies checkout options (may be NULL)
318325
* @return 0 on success, GIT_EUNBORNBRANCH if HEAD points to a non

0 commit comments

Comments
 (0)