5

Is there a way to git pull until there is something to pull.

Say i'm waiting for a collegue to push his latest changes, since i'm impatient and not looking at his screen, i just run watch git pull until i see something has been pulled, but i could miss the moment and waste a little more time than necessary. (note: yes, this is a very minor inconvenience, but an inconvenience still :) )

git pull does not seem to have a different return value whether it has actually pulled something, but maybe there's some obscure, undocumented option that i don't know about?

EDIT: Thanks for the answers, i added this to my .zshrc:

alias gitpullwait="git pull | grep "Already up-to-date" > /dev/null; while [ $? -ne 1 ]; do git pull | grep "Already up-to-date" > /dev/null; done; notify-send Pull f$

It looks ugly but it works for me.

iCart
  • 2,179
  • 3
  • 27
  • 36

3 Answers3

1

The usual way is to have a local listener which will detect a webhook (set on the server side).
That webhook would send a JSON payload that the local listener can interpret and act upon.

The link I mention is for a GitHub repo, BitBucket has its own version (POST hook).

For a private server, you would setup a post-receive hook to push to your workstation a JSON message signaling the latest push.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

There are a few ways to go about this, depending on your situation:

  1. Configure a git hook on your friend's machine to SSH into yours and execute a git pull upon completion of push - not recommended but an option. http://git-scm.com/book/en/Customizing-Git-Git-Hooks
  2. Configure a git hook on the git server 'post-receive' to SSH into your machine and execute a git pull - recommended if you can actually set git hooks on your git server. How to set up a Git hook so that after pushing to ssh://peter@foo.com/~/bar.com.git, it will go to ~/bar.com and do a git pull?
  3. Write a cron job to execute git pull on your machine every set interval - the not-very-performance-minded but fast approach to solving this issue. https://help.ubuntu.com/community/CronHowto

I would recommend option #2 if you have access to the remote repos server. Just remember, that unless you want this behaviour to happen always you will need to delete the hook afterwards.

Community
  • 1
  • 1
SimpleAnecdote
  • 765
  • 9
  • 17
1

You can pipe git output to awk/grep to look for the message that would have been printed if there's a non empty pull, and then use notify-send to flash a notification message on your desktop.

Also I'd recommend not doing git pull with the script, instead do a git fetch with the script and then merge manually so you don't get unexpected merging issues.

Lie Ryan
  • 62,238
  • 13
  • 100
  • 144