
This assumes:
- You have an ArgoCD server up and running. If not, check out my article Install Red Hat OpenShift GitOps Operator using the console (Argo CD)
- You have installed the ArgoCD CLI.
- You are able to log into ArgoCD using the CLI. If not, check out my article Log into ArgoCD using the CLI on OpenShift
The argocd repo list command can be used to list the repo's you have added to ArgoCD.
~]$ argocd repo list
TYPE NAME REPO INSECURE OCI LFS CREDS STATUS MESSAGE PROJECT
git foo-bar https://github.com/foo/bar.git false false false false Successful default
Assuming the repo you want to add has not already been added to ArgoCD, the argocd repo add command can be used to add the repo to ArgoCD. If the repo is a public repo, you should be able to add the repo without having to provide any sort of authentication, such as a username and password.
argocd repo add https://github.com/foo/bar.git
Or in the ArgoCD console at Settings > Repositories > Connect Repo.

For private repos, you need to authenticate. If using the HTTPS URL for the private repo, it's pretty common to provide a username and password.
argocd repo add https://github.com/foo/bar.git --username john.doe --password itsasecret
If adding the repo using the console, at Settings > Repositories > Connect Repo there is no option to provide a username and password, which is totally weird. However, you can go ahead and add the repo without including the username and password. Then at Settings > Repositories, select the repo and the panel that appears has an Edit button that allows you to provide the username and password.

Or you can use an Access Token, such as a GitHub Personal Access Token (PAT).

When using an Access Token, the username must be a non empty string such as a single whitespace and password will be the Access Token.
argocd repo add https://github.com/foo/bar.git --username ' ' --password 'ghp_ggEVZkS0N2mzlGABCK0pO3C123CSmS0oFNeX'
If adding the repo using the console, at Settings > Repositories > Connect Repo there is no option to provide a username and password, which is totally weird. However, you can go ahead and add the repo without including the username and password. Then at Settings > Repositories, select the repo and the panel that appears has an Edit button that allows you to provide the username and password. Since username must be a non-empty string, you will need to click on the username field and press the spacebar once so that the username contains a single whitespace. Yep, that's counter intuitive. Hopefully the ArgoCD folks eventually address this.

To add a repo using SSH, you will use an SSH private key. ArgoCD version 2.4 uses OpenSSH version 8.9. OpenSSH version 8.8 dropped support for ssh-rsa. The argocd --version command can be used to display the version of ArgoCD you are using.
~]$ argocd version
argocd: v2.13.2+dc43124
If you are using ArgoCD version 2.4 or higher, you must not create an RSA key. Instead, you will almost always go with an ed25519 SSH public/private keypair.
You may also need to ensure that the SSH key is an OpenSSH private key and has comment argocd (check out this article for more details on this). The ssh-keygen command can be used to create the OpenSSH public/private keypair.
ssh-keygen -t ed25519 -N '' -C argocd -f $HOME/.ssh/argocd
In this scenario, you would also need to add the SSH key in your GitHub account.

And then you can add the repo using the SSH private key.
argocd repo add git@github.com:foo/bar.git --ssh-private-key-path $HOME/.ssh/argocd
Or in the ArgoCD console at Settings > Repositories > Connect Repo.

Or you can create a YAML file that will be used to create a Kubernetes or OpenShift secret. The secret will add the repo to ArgoCD. For example, here is what you could have in your YAML file to add a GitHub repo to ArgoCD using an SSH key for the authentication to the GitHub repo.
apiVersion: v1
stringData:
name: my-repo
project: my-project
type: git
url: https://github.com/foo/bar.git
proxy: https://proxy.example.com # optional
sshPrivateKey: |
-----BEGIN OPENSSH PRIVATE KEY-----
MIIJK.....xdi3fPx
-----END OPENSSH PRIVATE KEY-----
kind: Secret
metadata:
annotations:
managed-by: argocd.argoproj.io
labels:
argocd.argoproj.io/secret-type: repository
name: my-repo
namespace: openshift-gitops
type: Opaque
And then the kubectl (Kubernetes) or oc (OpenShift) apply command can be used to create a secret from a YAML file.
~]$ oc apply -f repo.yml
secret/my-repo created
It's pretty common to give the repo a name and to map the repo to an ArgoCD project.
argocd repo add git@github.com:foo/bar.git \
--ssh-private-key-path ~/.ssh/id_rsa \
--name my-repo \
--project default
If you want ArgoCD to use a proxy to connect to the repo the --proxy option can be used.
argocd repo add git@github.com:foo/bar.git \
--ssh-private-key-path ~/.ssh/id_rsa \
--name my-repo \
--project default \
--proxy https://proxy.example.com
Or in the ArgoCD console at Settings > Repositories > Connect Repo and entry the http or https proxy URL.

Did you find this article helpful?
If so, consider buying me a coffee over at