0

I want to be able to pull down my source code from GitHub automatically, but currently doing it manual using the process below.

Currently i have to do this by going

$ sudo -i

Then I CD to my directory, once in I run the following command

$ git pull origin master

the command then asks for me to enter my key password

Enter passphrase for key '/root/.ssh/id_rsa':

This then pulls the latest code down from GitHub.

Liam
  • 47
  • 8

1 Answers1

0

A beginning note: does your repo really need to be pulled as root? Why? It's probably not a good idea to be doing that.

Github supplies https pull links that anyone can use to pull without needing a key. So, we can add another remote, used specifically for this purpose, that pulls using the https link.

git remote add autopull https://github.com/<user>/<repo>.git

Now you can change your pull command to:

git pull autopull master

From there, you can put it in .profile, .bash_profile, .bashrc, or maybe even a cron script. You haven't specified how you want to automate it, though, so I can't give any specific examples.

It should be noted that this can only work for public repositories. If this is a private repository, you should create another keypair that has no passphrase required. If it isn't your default keypair you can make use of a trick.

ssh-agent bash -c 'ssh-add /path/to/yourkey; git pull autopull master'

Or another answer to the same question:

GIT_SSH_COMMAND='ssh -i /path/to/yourkey' git pull autopull master
Community
  • 1
  • 1
Kitlith
  • 21
  • 3