How to Cache the Source Code directory


Bitrise does not do automatic git/source code caching, unless you configure it for yourself. This is part of our Security policy too (that we don’t store your code and we never access it outside of the ephemeral build VMs):

You can of course configure the source to be cached, a very simple / minimal example:

    - activate-ssh-key@3.1.1:
    - cache-pull@0.9.2: {}
    - git-clone@3.4.3:
        - reset_repository: 'Yes'
    - cache-push@0.9.4:
        - cache_paths: "$BITRISE_SOURCE_DIR"

​Basically you should add the Cache:Pull step before the Git Clone step, and a Cache:Push step after the Git Clone step.
If all you want to cache is the src dir then Cache:Push can be right after Git Clone, if you’ll want to cache other things then move it to be the last step in the workflow (or when all the things you want to cache are available).

So, once you added the Cache:Push and Cache:Pull steps:

  1. Select the Cache:Push step, and specify the Cache paths input of the step: $BITRISE_SOURCE_DIR
  2. That’s pretty much all what’s required, but it’s also a good idea to enable the Git Clone step’s “clear before checkout” option
    1. select the Git Clone step
    2. and search for the Reset repository option
    3. then set it to Yes.
    4. This will ensure that the step will clear out any previously checked out files before the new checkout (e.g. to remove files which got .gitignored, but were not in the previously cached state, and other similar edge cases).

If you have any questions just let us know! :wink:


Git clone step is very slow
Git-lfs caching, is it possible?
Context sharing between parent and child build
Git clone - does not fast forward to the lastest of a branch

Hi @viktorbenei,

Thanks for your post and sorry if my one is a silly questions but I’m newbie in Bitrise and for me it’s not clear how the Bitrise cache works. My questions are:

  1. In the example scripts reported previously in this page and in all the example I found on internet, when we call the cache-pull we don’t report any source/cache folder as input, but in cache push is required the cache_path, is the pull script pulling everything is cached?
  2. Is it possible to create several cache in the same script and in the same branch? For example one cache for node_modules, one for ruby gems, one for the cordova plugins… if it’s possible, is there an example how to do it? Can we keep it independents each other?
  3. Is it possible to define which folder we want to push/pull and where we store the cache?

Thanks in advance for your answers.



Hy there, sorry for the late reply

1, the cache pull will pull the cached things into the folder the previous step got them from (i don’t really understand how, it’s magic)

2, gems and cordova plugins are cached by default if you have the steps in, node_modules is not advised to be cached because it in most cases is filled with garbage dependencies and can cause errors.

3, you can define what to cache in the cache push step, we store it on our own servers