Bash Script to Push/Pull from Private Git Repository?

三世轮回 提交于 2020-01-01 05:20:14

问题


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?


回答1:


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 git@github.com: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.



来源:https://stackoverflow.com/questions/10421430/bash-script-to-push-pull-from-private-git-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!