I'm trying to create a bash script that initializes a server and clones a git repository as part of initialization.
The installing user will set a personal access token (PAT) as an environment variable $TOKEN to clone via script. I want each subsequent user that pulls or pushes code to this cloned repository to set their PAT via environment variable $TOKEN, instead of using the original PAT the installer used.
However, when the script clones the repository gitconfig stores the interpreted value of the $TOKEN instead of variable $TOKEN so any subsequent pull/push uses the original installer's PAT.
i.e. when I do:
git clone https://oauth2:[email protected]/repo.git
gitconfig says:
[remote "origin"]
url = https://oauth2:[email protected]/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
when I want it to say:
[remote "origin"]
url = https://oauth2:[email protected]/repo.git
fetch = +refs/heads/*:refs/remotes/origin/*
I can't figure out how to force each user to use their token each time in a simple way.
Any ideas? Thanks
.git/configso havinghttps://oauth2:[email protected]/repo.gitin the config is meaningless. The only way is to have the URL in the shell script where shell expands the variable. Aftergit clonereset the URL withgit remote set-url origin https://gitlab.com/repo.git