# Cache .git versus persist\_to\_workspace

**URL:** <https://discuss.circleci.com/t/cache-git-versus-persist-to-workspace/22363>\
**Category:** Build Environment\
**Created:** [May 15, 2018, 8:59pm UTC](https://discuss.circleci.com/t/cache-git-versus-persist-to-workspace/22363 "2018-05-15T20:59:44Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![claytron5000](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/claytron5000/32/18403_2.png) [@claytron5000](https://discuss.circleci.com/u/claytron5000)\
**Post date:** [May 15, 2018, 8:59pm UTC](https://discuss.circleci.com/t/cache-git-versus-persist-to-workspace/22363/1 "2018-05-15T20:59:44Z")

</div>

Using the v2.0, I’m caching my .git directory in the `build` job, then in subsequent jobs I’m retrieving the cache and checkout it out. Wouldn’t it be fast to just persist to workspace the working directory? (The answer is yes, because I’ve tried it, I’m just not sure why the docs seems to suggest otherwise)

---

<div class="post-metadata">

**Author:** ![FelicianoTech](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/felicianotech/32/21348_2.png) [@FelicianoTech](https://discuss.circleci.com/u/FelicianoTech)\
**Post date:** [May 22, 2018, 5:38pm UTC](https://discuss.circleci.com/t/cache-git-versus-persist-to-workspace/22363/2 "2018-05-22T17:38:39Z")

</div>

Where in the Docs do you see this?

What is the ultimate point in moving your `.git/` directory into additional jobs?

---

<div class="post-metadata">

**Author:** ![claytron5000](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/claytron5000/32/18403_2.png) [@claytron5000](https://discuss.circleci.com/u/claytron5000)\
**Post date:** [May 22, 2018, 8:48pm UTC](https://discuss.circleci.com/t/cache-git-versus-persist-to-workspace/22363/3 "2018-05-22T20:48:37Z")

</div>

It’s referenced in the docs: [https://circleci.com/docs/2.0/caching/#source-caching](https://circleci.com/docs/2.0/caching/#source-caching)

---

<div class="post-metadata">

**Author:** ![claytron5000](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/claytron5000/32/18403_2.png) [@claytron5000](https://discuss.circleci.com/u/claytron5000)\
**Post date:** [June 4, 2018, 1:57pm UTC](https://discuss.circleci.com/t/cache-git-versus-persist-to-workspace/22363/4 "2018-06-04T13:57:46Z")

</div>

I’m still definitely interested in this idea. I’m getting the sense from @FelicianoTech 's comment that this is not actually the recommended way to persist a codebase through jobs.

---

<div class="post-metadata">

**Author:** ![FelicianoTech](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/felicianotech/32/21348_2.png) [@FelicianoTech](https://discuss.circleci.com/u/FelicianoTech)\
**Post date:** [June 4, 2018, 2:41pm UTC](https://discuss.circleci.com/t/cache-git-versus-persist-to-workspace/22363/5 "2018-06-04T14:41:41Z")

</div>

The idea behind this is to cache your Git repo for pulling from GitHub via the `checkout` step. The [Workspaces Doc](https://circleci.com/docs/2.0/workflows/#using-workspaces-to-share-data-among-jobs) shows that Workspaces typically are the fastest way to move data between `jobs`.

---

<div class="post-metadata">

**Author:** ![floscher](https://avatars.discourse-cdn.com/v4/letter/f/e0b2c6/32.png) [@floscher](https://discuss.circleci.com/u/floscher)\
**Post date:** [June 4, 2018, 4:43pm UTC](https://discuss.circleci.com/t/cache-git-versus-persist-to-workspace/22363/6 "2018-06-04T16:43:41Z")

</div>

Please note that the `checkout` step is currently broken when caching the `.git` directory and you try to build a tag:

> [@Checkout fails on git-tags, when .git directory is already present](https://discuss.circleci.com/t/checkout-fails-on-git-tags-when-git-directory-is-already-present/22437):
>
> For one of my projects I cache the .git directory between builds, similar to [https://circleci.com/docs/2.0/caching/#source-caching](https://circleci.com/docs/2.0/caching/#source-caching) Now I found out that the checkout step fails as soon as the build is triggered by pushing a git-tag to GitHub: [https://circleci.com/gh/JOSM/wikipedia/37#action-103](https://circleci.com/gh/JOSM/wikipedia/37#action-103) This is caused by line 39 in the checkout.sh: git fetch --force origin "refs/tags/${CIRCLE\_TAG}" This line fetches the commit associated with the tag, but does not create the tag in the local repositor…

---

<div class="post-metadata">

**Author:** ![claytron5000](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/claytron5000/32/18403_2.png) [@claytron5000](https://discuss.circleci.com/u/claytron5000)\
**Post date:** [June 4, 2018, 8:51pm UTC](https://discuss.circleci.com/t/cache-git-versus-persist-to-workspace/22363/7 "2018-06-04T20:51:25Z")

</div>

that makes sense, thanks.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/circleci/original/3X/5/1/511608acda8e85906e15909b57bd0a46c1dbe291.png) [@system](https://discuss.circleci.com/u/system)\
**Post date:** [September 2, 2018, 8:51pm UTC](https://discuss.circleci.com/t/cache-git-versus-persist-to-workspace/22363/8 "2018-09-02T20:51:30Z")

</div>

Closed on September 2, 2018, 8:51pm UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
