# Git Fetch Flags

**URL:** <https://forum.buildkite.community/t/git-fetch-flags/2920>\
**Category:** Elastic CI Stack for AWS\
**Created:** [May 15, 2023, 1:30am UTC](https://forum.buildkite.community/t/git-fetch-flags/2920 "2023-05-15T01:30:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamsjordn](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/jamsjordn/32/1341_2.png) [@jamsjordn](https://forum.buildkite.community/u/jamsjordn)\
**Post date:** [May 15, 2023, 1:30am UTC](https://forum.buildkite.community/t/git-fetch-flags/2920/1 "2023-05-15T01:30:36Z")

</div>

Hi,

We use a monorepo that needs to compare the latest origin for the main branch, however Buildkite only grabs the origin for the branch that triggered the build. If the machine is fresh this is fine because the clone will have fetched the latest for main, but with on demand machines they have stale main branches.

I’ve tried using the git-fetch-flags [Buildkite Agent configuration v3 | Buildkite Documentation](https://buildkite.com/docs/agent/v3/configuration#git-fetch-flags) however adding `--all` doesn’t work as it conflicts with the explicit fetch of only one branch.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/buildkite1/original/2X/2/20322228a55c5bed2daec1e00ff88332b085215e.png)

Is there something I am missing that would make this work? Or since this flag is experimental, could something be added that says if --all is added to the flags then don’t try and fetch only the current branch?

Cheers,  
James

---

<div class="post-metadata">

**Author:** ![james.s](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/james.s/32/1305_2.png) [@james.s](https://forum.buildkite.community/u/james.s)\
**Post date:** [May 15, 2023, 5:09am UTC](https://forum.buildkite.community/t/git-fetch-flags/2920/2 "2023-05-15T05:09:22Z")

</div>

Hey @jamsjordn!

Thanks for the message- hope you are well 🙂

Just wanted to confirm if you are setting the `-all` flag as part of an agent configuration? The `BUILDKITE_GIT_FETCH_FLAGS` as you’ve most likely seen in the docs is agent level configuration, so loading it with a Agent level hook/config export would suffice (by default the flags are `-v --prune`

If you wanted to fetch everything from upstream, a `git fetch -v --prune origin` should do the trick.

Hope that helps!

---

<div class="post-metadata">

**Author:** ![jamsjordn](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/jamsjordn/32/1341_2.png) [@jamsjordn](https://forum.buildkite.community/u/jamsjordn)\
**Post date:** [May 15, 2023, 8:04am UTC](https://forum.buildkite.community/t/git-fetch-flags/2920/3 "2023-05-15T08:04:22Z")

</div>

Hi,

I was using a pre-checkout hook to update `BUILDKITE_GIT_FETCH_FLAGS`  
I was using it through a community plugin but everything seems correct there [GitHub - Hivebrite/git-flags-buildkite-plugin: Plugin to set BUILDKITE\_GIT\_CLONE\_FLAGS & BUILDKITE\_GIT\_FETCH\_FLAGS](https://github.com/Hivebrite/git-flags-buildkite-plugin)

I’ve just tried using `-v --prune origin` but when the actual `git fetch` is performed ` -- origin be41afea5b706817ffb1b828deea74fffcd34dc9` gets added to it resulting in

 ![image](https://us1.discourse-cdn.com/flex016/uploads/buildkite1/original/2X/9/9d115fe799847a007566dfbd1b6ba6fc5ff3ebde.png)

From what I can tell in [agent/git.go at main · buildkite/agent · GitHub](https://github.com/buildkite/agent/blob/main/bootstrap/git.go) on line 118, the git fetch always appends the ` -- origin hash` part of the command and so through this I don’t think it’d currently be possible to fetch both the current branch and master through these means.

---

<div class="post-metadata">

**Author:** ![suma](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/suma/32/1306_2.png) [@suma](https://forum.buildkite.community/u/suma)\
**Post date:** [May 15, 2023, 4:43pm UTC](https://forum.buildkite.community/t/git-fetch-flags/2920/4 "2023-05-15T16:43:00Z")

</div>

@jamsjordn

We believe the reason you are seeing `-- origin be41afea5b706817ffb1b828deea74fffcd34dc9` gets added is because your build is for a commit push event. Is that correct ? Please can you send your build url to [support@buildkite.com](mailto:support@buildkite.com) as that would help us check this further.

---

<div class="post-metadata">

**Author:** ![jamsjordn](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.buildkite.community/jamsjordn/32/1341_2.png) [@jamsjordn](https://forum.buildkite.community/u/jamsjordn)\
**Post date:** [May 15, 2023, 11:39pm UTC](https://forum.buildkite.community/t/git-fetch-flags/2920/5 "2023-05-15T23:39:03Z")

</div>

Hi,

This is a build for a commit push, I’ve sent through the build URL to that email.

Also we are using Bitbucket if that helps, I can see there is some GitHub specific code that would not be applied to us.
