Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

checkout remote branch example #777

@jollyjokester

Description

@jollyjokester

Hey,
I'd appreciate some example of how we can properly checkout the branch that is present on the remote.

EDIT:
For the future reference, a dummy example:

   url := os.Args[1]
   directory := os.Args[2]
   branch := os.Args[3]
    
    r, _ := git.PlainClone(directory, false, &git.CloneOptions{
        URL: url,
    })
    w, _ := r.Worktree()

    err := r.Fetch(&git.FetchOptions{
        RefSpecs: []config.RefSpec{"refs/*:refs/*", "HEAD:refs/heads/HEAD"},
    })
    if err != nil {
        fmt.Println(err)
    }
  
	err = w.Checkout(&git.CheckoutOptions{
		Branch: fmt.Sprintf("refs/heads/%s", branch),
        Force: true,
    })
    if err != nil {
        fmt.Println(err)
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions