Reputation: 33409
I want to run something in the background which basically does a git pull --rebase
whenever some changes happen in my remote branch. Most of the time it work silently in the background if there are no conflicts. In there is a conflict it just leaves me in the rebase-resolve-conflict stage and until I resolve everything it waits. How do I do this? Is there an existing software that already does this?
Upvotes: 11
Views: 3987
Reputation: 62466
If you don't have control on the remote repository, one solution is to use crontab to run periodically git fetch
or maybe even a git pull --rebase
as you propose. The exact command to choose depends on your workflow, personally I prefer to use a git fetch
because I can decide when and how to merge or rebase.
To run the command periodically run:
crontab -e
And add a line such as:
* * * * * git -C PATH_TO_LOCAL_REPO fetch
or
* * * * * git -C PATH_TO_LOCAL_REPO pull --rebase
This will run the git command every minutes with your user permissions.
If you want to apply the git command on a list of repository, you can can add the line:
* * * * * /home/myself/scripts/git-refresh.sh
where git-refresh is a script that apply on all your repositories.
The -C
option allows you to run a git command without changing directory. From the man page:
-C <path>
Run as if git was started in "path" instead of the current working directory.
Upvotes: 6
Reputation: 7591
This process called as Syncing a fork
Sync a fork of a repository to keep it up-to-date with the upstream repository. Unfortunately GitHub doesn't have any automatic sync feature. But, it is trivial to add as a cron job on a server so that you don't have to do it manually. For instance:
cd /srv/mirrorrepo ; git fetch upstream master ; git push origin master
Following plugin might help
https://github.com/trilbymedia/grav-plugin-git-sync
Upvotes: 0