0

I have a repo which needs to be cloned daily for some data. Is there a way in golang using go-git library to clone the repo only once and update the repo using git pull?

Pradeep
  • 1,198
  • 3
  • 12
  • 22

1 Answers1

3

Sure, there's Worktree.Pull() method exactly for that.

    // Open already cloned repo in path
    r, err := git.PlainOpen(path)
    
    // Get the working directory
    w, err := r.Worktree()
    
    // Pull from origin
    err = w.Pull(&git.PullOptions{RemoteName: "origin"})

(skipped error checking for better readability)

blami
  • 6,588
  • 2
  • 23
  • 31