Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash Script to Push/Pull from Private Git Repository?

I'm trying to find a way that I can write a bash script that will auto-pull from our Private Github Repository every midnight and update our development site.

Our repo is private for obvious reasons and anything close that I've found always asks for the passphrase. Our server has it's own Github Account that it uses to push and pull from the repository but I just don't know how to do that automatically.

Can anyone point me in the right direction?

like image 918
Peter Avatar asked May 02 '12 20:05

Peter


1 Answers

In order to automate your push/pull, you'll need to set up passwordless authentication. To do so, you use ssh (instead of https). If you haven't used ssh with github, or at all, before, then you'll need to perform a few steps to get things configured.

On your machine, generate an ssh key:

$ ssh-keygen -t rsa

Make sure you leave the passphrase field blank. This leaves the local private key unencrypted, but no less secure for the actual communication over the internet.

Then, upload ~/.ssh/id_rsa.pub to github under Account Settings | SSH Keys

Now you should be able to push and pull from that machine without a password. Try it out:

git clone [email protected]:user/repo.git

You can then put these commands in your bash script as appropriate. If you need to do this for multiple machines, you'll need to upload each key, or copy the private key (~/.ssh/id_rsa) to each one.

See github help for more info. Also take a look at the deploy keys page, as that may provide better granularity of security for your situation.

like image 182
djs Avatar answered Oct 27 '22 11:10

djs