DevOps / GitLab CI Basics Interview Questions
What is the 'GIT_STRATEGY' variable in GitLab CI and what are the options?
The GIT_STRATEGY variable controls how GitLab CI fetches your repository's code at the start of each job. Choosing the right strategy balances freshness of code against job startup speed.
| Value | Behaviour | Speed | Use case |
|---|---|---|---|
| fetch (default) | Fetches only new commits; reuses existing clone | Fast | Most jobs |
| clone | Full fresh clone every time | Slow | When clean state is required |
| none | Skips Git entirely; no repo code | Fastest | Jobs that don't need repo code (deploy from artifact) |
# Set globally for all jobs: variables: GIT_STRATEGY: fetch # default - fast incremental fetch # Override for a specific job: clean-build: variables: GIT_STRATEGY: clone # ensure completely fresh checkout script: - make clean && make build # Skip checkout for deploy-only jobs: deploy-from-artifact: variables: GIT_STRATEGY: none # no git checkout needed script: - echo "Using artifact from build job..." - ls dist/ # artifact already downloaded - ./deploy.sh # Related: control submodule fetching variables: GIT_SUBMODULE_STRATEGY: normal # clone/fetch submodules too
GIT_DEPTH: the related variable GIT_DEPTH controls shallow clone depth. Setting GIT_DEPTH: "1" fetches only the latest commit (no history), which is significantly faster for large repositories. Setting it to 0 disables shallow cloning and fetches full history.
More Related questions...