Linux – How to configure automatic password handling for git commands:

command linegitlinuxpassword-managementpasswords

I have an automatic build script for my build server that builds Android applications.
As part of this building process, I need to pull the current sources from the repository to make a release and make a push command at the end of the build process to update the repository with the files that were changed during the build process by the build server.

So I have to build the following bash script:

#!/bin/bash
clear
echo "Start of Pull command"
git pull
echo "End of Pull command"
echo "Start of incrementedRelease build"
gradle incrementedRelease
echo "End of incrementedRelease build"
echo "Start of Commit command"
git commit -a -m "======================== Commit to change Manifest Version ======================"
echo "End of Commit command"
echo "Start of Push command"
git push
echo "End of Push command"

The issue is in the command of git push and git pull, git prompts me for a password.

Now I tried to run this command to create a password store, before entering the password for git.

  sudo git config --global credential.helper store

with and without the sudo command, but next time I run the script it's still prompts me for a password.

Could some one tell me how I can store the git password so I won't be prompted for each pull or push command? preferably take it from a file, and not use ssh, because I don't have access to the git server in order to generate the keys there..

UPDATE:
This are the folder I have in the user's home folder:

enter image description here

Thanks in advance.

Best Answer

Setting the credential.helper config option to store should definitely do what you're asking for. You'll still have to enter your username and password at least once for git-credential-store to store it in a file (~/.git-credentials by default), but then you shouldn't need to anymore.

Note that the file storing your credentials won't be encrypted and anybody managing to read it would then get the user's permissions on the repository, so it might a good idea to set up a read-only user especially for this and not globally set the credential.helper config option to store.

If you're using a web interface to your repository (Github, Bitbucket, Gitlab, etc), you might also have the (preferred, imho) possibility to set up a SSH deploy key through the repository settings to provide secure, read-only access.

Related Question