code: func (w *Worktree) Checkout(opts *CheckoutOptions) error {
  	if err := opts.Validate(); err != nil {
  		return err
  	}
  
  	if opts.Create {
  		if err := w.createBranch(opts); err != nil {
  			return err
  		}
  	}
  
  	c, err := w.getCommitFromCheckoutOptions(opts)
  	if err != nil {
  		return err
  	}
  
  	ro := &ResetOptions{Commit: c, Mode: MergeReset}
  	if opts.Force {
  		ro.Mode = HardReset
  	}
  
  	if !opts.Hash.IsZero() && !opts.Create {
  		err = w.setHEADToCommit(opts.Hash)
  	} else {
  		err = w.setHEADToBranch(opts.Branch, c)
  	}
  
  	if err != nil {
  		return err
  	}
  
  	return w.Reset(ro)
  }
docs: // Checkout switch branches or restore working tree files.