Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash script to automate Git pull

Tags:

git

bash

git-bash

I want to automatically pull from Git. For some reasons it is not possible to automate the password thing in the server I am using. So it needs to be done by a Bash file. Now my Bash coding is not that good. Then it is possible to enter the passphrase for the SSH key. But I have really no clue what to do...

#!/bin/bash cd . public_html/auto_deploy/foldername && git fetch --all && git checkout --force "origin/master"

The above is not working... And then it needs to enter the passphrase, and I have no idea what to do then... How can I do this?

like image 686
Robert Dam Avatar asked Aug 28 '26 19:08

Robert Dam


2 Answers

Fortunately and according to the core Git documentation, you can use the following command to save your credentials for later on use - instead of typing it each time when prompted.

git config credential.helper store

Using this helper will store your passwords unencrypted on disk, protected only by filesystem permissions. This command stores credentials indefinitely on disk for use by future Git programs.

You probably don’t want to invoke this command directly; it is meant to be used as a credential helper by other parts of git

Interesting to check: Git Credentials

like image 116
Viktova Avatar answered Aug 30 '26 11:08

Viktova


If you want to do Git pull from a shell script, you need to use it like this:

git pull https://username:password@git_hostname.com/my/repository
like image 39
Naga Raju Avatar answered Aug 30 '26 11:08

Naga Raju