'golang git - Is there a way to pull latest from remote branch if the repo is already cloned rather than cloning it again
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?
Solution 1:[1]
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)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | blami |
