0

I'm trying to write a shell script in linux that pulls all the files from a git repository that were committed in the latest commit. The way I do that is to run a git fetch to get the latest commit inof, then git show to capture the file names, then I pull the specific files individually. The script needs to be run by multiple users, all with access to the git repo. I had it set up to ask for the username and password, then would run:

git fetch "https://USER:PASSWORD@GIT_URL"

This would work but was not getting the latest commit always. I found that git fetch (no parameters) was working and found this Q/A explaining the difference: git fetch vs. git fetch origin master have different effects on tracking branch

So, I changed the script so it just calls git fetch, and the user enters his/her password when prompted (it asks, Password for, "https://USER@GIT_URL": ). The issue now is that other users are being asked for MY password. I thought the USER would be taken from the system login. Does anyone know how I can get ONLY the files changed in the latest commit without running into these issues? Thank you.

user3813942
  • 311
  • 1
  • 3
  • 13

1 Answers1

0

When you use Git URLs in script on a shared server, it is recommended to use SSH URL instead of HTTPS URL. All you need to do is create SSH key and add the public key on Git repository. This will enable to access the git repository with SSH URL.

if you don't mind sharing the password, another way of doing is add ~/.netrc file on the remote server with following configuration. This is not recommended.

machine https://gir.url
login xxx
password xxx
Ela
  • 419
  • 1
  • 6
  • 20