github.com/purpleclay/gitz@v0.8.2-0.20240515052600-43f80eea2fe1/docs/git/pull.md (about) 1 --- 2 icon: material/arrow-left-bold-box-outline 3 title: Pulling the latest changes from a remote 4 description: Pull all changes from a remote and integrate them into the current working directory 5 --- 6 7 # Pulling the latest changes from a remote 8 9 [:simple-git:{ .git-icon } Git Documentation](https://git-scm.com/docs/git-pull) 10 11 Pull all changes from a remote into the current working directory. Ensures the existing repository keeps track of changes and stays in sync. 12 13 ## Pull the latest changes from the current Branch 14 15 Calling `Pull` will attempt to sync the current branch with its counterpart from the remote: 16 17 ```{ .go .select linenums="1" } 18 package main 19 20 import ( 21 "fmt" 22 "log" 23 24 git "github.com/purpleclay/gitz" 25 ) 26 27 func main() { 28 client, _ := git.NewClient() 29 30 // a new file was added to the hierarchy at the remote: 31 // > folder 32 // > c.txt 33 34 out, err := client.Pull() 35 if err != nil { 36 log.Fatal("failed to pull latest changes from remote") 37 } 38 39 fmt.Println(out) 40 } 41 ``` 42 43 Printing the output from this command: 44 45 ```{ .text .no-select .no-copy } 46 remote: Enumerating objects: 5, done. 47 remote: Counting objects: 100% (5/5), done. 48 remote: Compressing objects: 100% (3/3), done. 49 remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 50 Unpacking objects: 100% (3/3), 300 bytes | 150.00 KiB/s, done. 51 From /Users/paulthomas/dev/./gitrepo 52 703a6c9..8e87f78 main -> origin/main 53 Updating 703a6c9..8e87f78 54 Fast-forward 55 folder/c.txt | 1 + 56 1 file changed, 1 insertion(+) 57 create mode 100644 folder/c.txt 58 ``` 59 60 ## Configuring fetch behavior 61 62 When pulling changes from a remote repository, a fetch happens before merging any changes. Configuring the behavior of this fetch is possible using the supported `WithFetch...` [options](./fetch.md). 63 64 For example, you can limit the fetched commit history with the `WithFetchDepthTo` option. 65 66 ## Providing git config at execution 67 68 You can provide git config through the `WithPullConfig` option to only take effect during the execution of a `Pull`, removing the need to change config permanently.