<p>I have an Airflow environment (v2.4.3) on Kubernetes and I want to sync it with a private git repo so that any changes I make to DAGs in my master branch get automatically picked up by my Airflow environment.</p>
<p>According to <a href="https://airflow.apache.org/docs/helm-chart/stable/manage-dags-files.html#mounting-dags-from-a-private-github-repo-using-git-sync-sidecar" rel="nofollow noreferrer">Airflow documentation</a>, I can use Git-sync sidecar along with an SSH key added to my private git repo and Airflow env to make it work.</p>
<p>However, given that I am constantly creating new private repos and Airflow environments, I am wondering if there is a more simple way of connecting my private git repos to their respective Airflow environment.</p>
<p>If I have a webapp managing my Airflow environments and have access to an OAuth token from Github after signing into my account (or any other git service), could I use that to connect my an Airflow environement and sync changes to any git repo of my choice under my account?</p>

<p>I was able to figure it out.</p>
<p>One can use <a href="https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token" rel="nofollow noreferrer">personal access tokens</a> as passwords provided by whatever git service the private repo is in along with the repo's username.</p>
<p>I just stored the personal access token as an Opaque secret in my Airflow K8s cluster and referenced that in my <a href="https://github.com/kubernetes/git-sync/tree/v3.6.5" rel="nofollow noreferrer">git-sync sidecar container yaml</a> definition which I included in my Airflow yaml deployment definition.</p>
<pre><code>      containers:
        - name: git-sync
          image: registry.k8s.io/git-sync/git-sync:v3.6.5
          args:
            - &quot;-wait=60&quot;
            - &quot;-repo=&lt;repo&gt;&quot;
            - &quot;-branch=master&quot;
            - &quot;-root=/opt/airflow/dags&quot;
            - &quot;-username=&lt;username&gt;&quot;
            - &quot;-password-file=/etc/git-secret/token&quot;
          volumeMounts:
            - name: git-secret
              mountPath: /etc/git-secret
              readOnly: true
            - name: dags-data
              mountPath: /opt/airflow/dags
      volumes:
        - name: dags-data
          emptyDir: {}
        - name: git-secret
          secret:
            secretName: github-token
</code></pre>
