Git Commands in Pipelines

I am learning about some features of az devops pipelines

Introduction

Recently, I came across some topics that helped me deepen my understanding of Git—especially in the context of CI/CD pipelines.

Running Git Commands in Pipeline Scripts

Git commands can be used within pipeline scripts that run on agents. For example, you might need to pull files from external Bitbucket repositories as part of your build workflow.

🔗 Using Git Commands in Azure Pipelines

What Does the checkout Step Do?

Here’s a typical Git workflow in an Azure pipeline:

1
2
3
4
git version
git lfs version
git init "/home/vsts/work/1/s/gitops-development"
git remote add origin https://tes@dev.azure.com/test/_git/gitops-development

To optimize configuration and metadata:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
git sparse-checkout disable
git config gc.auto 0                         # Disable automatic garbage collection
git config core.longpaths true              # Enable long file paths
git config --get-all http.https://test@dev.azure.com/test/_git/gitops-development.extraheader
git config --get-all http.extraheader
git config --get-regexp .*extraheader
git config --get-all http.proxy
git config http.version HTTP/1.1

# Perform a shallow fetch (only the latest commit)
git --config-env=http.extraheader=env_var_http.extraheader fetch \
  --force --tags --prune --prune-tags --progress \
  --no-recurse-submodules origin --depth=1

Then, the pipeline checks out a specific commit (or branch):

1
git checkout --progress --force refs/remotes/origin/123

This checkout is done on a temporary branch that exists only during the pipeline execution.

Are There Any Constraints?

Yes, there are some permission-related constraints. Pipelines can access all repositories in your project or organization if you configure two specific settings.

🔗 Pipeline Access Tokens and Scope

What Did I Learn from This?

I didn’t learn everything, but this definitely sparked more curiosity around optimizing repository cloning.

For example, shallow cloning is a great way to reduce clone time, bandwidth usage, and overall pipeline overhead:

1
git fetch --depth=1

or directly:

1
git clone --depth=1

This fetches only the latest commit instead of the full history—a small tweak that can make a big difference.

Conclusion

I’m excited to keep learning more about how things work behind the scenes. It’s always rewarding to discover these small “aha!” moments during daily work.

Offtopic

adopt

comments powered by Disqus
Built with Hugo
Theme Stack designed by Jimmy