user6419293
user6419293

Reputation:

How To Set Up Auto Updating Git

I'm using Github to store my projects, and would like to know if there is a way for me to get my repository to automatically update in real time.

To clarify what I mean, I'm currently using the good old "git clone" "git add" "git commit" "git push" technique, but it's becoming rather tedious.

What mechanism can I put in place to achieve that?

Upvotes: 2

Views: 11409

Answers (1)

VonC
VonC

Reputation: 1324198

On the push side, you can use a local .git/hooks/post-commit that includes:

#!/bin/sh
git push origin master

(assuming here you are pushing from master: you have other options at "How to automatically push after committing in git?")


If you want a local repo always up-to-date with a remote GitHub repo, you can setup a webhook which will listen for push events and automatically pull for you.

See for instance this webhook (or this one):

<?php
// Use in the "Post-Receive URLs" section of your GitHub repo.
if ($_SERVER['HTTP_X_GITHUB_EVENT'] == 'push') {
  shell_exec( 'cd /srv/www/git-repo/ && git reset --hard HEAD && git pull' );
}
?>hi

The OP NodziGames decided in the comments to go for a more "on demand" approach:

create a Makefile where I can clone, add new files, commit and push via a single command.

Upvotes: 2

Related Questions