Fetch all remote changes from a remote repository without integrating (merging) them into the current repository (working directory). Ensures the existing repository only tracks the latest remote changes.
packagemainimport("log"git"github.com/purpleclay/gitz")funcmain(){client,_:=git.NewClient()_,err:=client.Fetch()iferr!=nil{log.Fatal("failed to fetch all changes from the remote")}}
packagemainimport("fmt""log"git"github.com/purpleclay/gitz")funcmain(){client,_:=git.NewClient()// Existing locally tracked tags: 0.1.0// Additional tags that exist at the remote: 0.2.0, 0.3.0_,err:=client.Fetch(git.WithTags())iferr!=nil{log.Fatal("failed to fetch all changes from the remote")}tags,err:=client.Tags()iferr!=nil{log.Fatal("failed to retrieve local repository tags")}for_,tag:=rangetags{fmt.Println(tag)}}
packagemainimport("fmt""log"git"github.com/purpleclay/gitz")funcmain(){client,_:=git.NewClient()// Existing locally tracked tags: 0.1.0// Additional tags that exist at the remote: 0.2.0, 0.3.0_,err:=client.Fetch(git.WithIgnoreTags())iferr!=nil{log.Fatal("failed to fetch all changes from the remote")}tags,err:=client.Tags()iferr!=nil{log.Fatal("failed to retrieve local repository tags")}for_,tag:=rangetags{fmt.Println(tag)}}
Limit the number of commits fetched from the tip of each remote branch history, using the WithDepthTo option. This can be used to deepen or shorten the existing history of a shallow cloned repository.
packagemainimport("fmt""log"git"github.com/purpleclay/gitz")funcmain(){client,_:=git.NewClient()_,err:=client.Fetch(git.WithDepthTo(2))iferr!=nil{log.Fatal("failed to fetch all changes from the remote")}repoLog,err:=client.Log()iferr!=nil{log.Fatal("failed to retrieve repository log")}for_,commit:=rangerepoLog.Commits{fmt.Println(commit.Message)}}
Printing the log results in:
feat: add initial support for git fetch
feat: extend pull options to control how change sets are retrieved
You can provide git config through the WithFetchConfig option to only take effect during the execution of a Fetch, removing the need to change config permanently.