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.

3
  • Are you writing $USER or your actual username? The environment variable should usually be set to the id of the user running the command. Commented Jun 18, 2018 at 16:33
  • how is you script different than a user running git pull in their respective local repositories? Commented Jun 18, 2018 at 17:44
  • This is run on a shared remote server. Commented Jun 19, 2018 at 12:15

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.