Basically am writing a crontab task that checks my remote git repository every 1 minute. If there is changes, it pulls them (to the local repo), go through each commit and does runs a grunt selenium task on each commit.
The part that am sort of stuck is how to find out if the remote git repository has new content and i need to pull!
you can use git remote update; git status -uno to check if your local branch is up-to-date with the origin one. It only gives the local status, not checking with the remote branch. Only gives local, but git remote update ; git status -uno did the trick!
You can check your current version of Git by running the git --version command in a terminal (Linux, macOS) or command prompt (Windows). If you don't see a supported version of Git, you'll need to either upgrade Git or perform a fresh install, as described below.
You can use git ls-remote
to find that out:
git ls-remote origin master
This command will get the latest sha-1 id of the master branch, you can specify as many branches as you want, or none to get them all. You can use that to compare with the local branch.
However, it might be more efficient to fetch all the changes so you don't have to do the same network operation twice:
git fetch origin
This way you will get the updates in 'origin/master', and you can compare with 'master' to see if there are updates. This doesn't merge or rebase, so once you have detected there are updates, you can do git pull
or git merge
or git rebase
, whatever it is that you want to do.
git fetch
git log ..origin/master --oneline | wc -l
It outputs the number of revisions (commits) that would be applied when pulling.
If it's greater than 0 it means that there is new content.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With