---
title: "Auto Notify Git Pull"
description: "Bash function to notify when entering a git directory with upstream changes. Practical notes and code examples on Auto in JS."
url: "https://h3manth.com/scribe/auto-notify-git-pull/"
canonical_url: "https://h3manth.com/scribe/auto-notify-git-pull/"
markdown_url: "https://h3manth.com/scribe/blog/auto-notify-git-pull.md"
publishDate: "2013-05-01T00:00:00.000Z"
author: "Hemanth HM"
category: "opensource"
tags: ["git","bash","cli"]
word_count: 99
reading_time_minutes: 1
x_markdown_tokens: 242
content_signal: "ai-train=yes, search=yes, ai-input=yes"
---

# Auto Notify Git Pull

> Bash function to notify when entering a git directory with upstream changes. Practical notes and code examples on Auto in JS.

A script that upon entering a directory asynchronously checks git remotes for updates.

```bash
function cd() {
  async() {
    { $2 $($1) }&
  }
  
  notify_callback() {
    [[ $1 > 0 ]] && echo "You have new stuff to pull!"
  }
  
  # If it's a git repo, check if we need to pull.
  if git rev-parse --is-inside-work-tree &>/dev/null; then
    async "git rev-list HEAD...origin/master --count" notify_callback
  fi
  
  builtin cd "$@"
}
```

Place this in your `.bashrc` to override the `cd` command.

**Better approach:**
(( $(git rev-list HEAD..@{u} --count) > 0 )) && echo "There are new things to merge"
```
