npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

git-auto-follow

v0.2.0

Published

Auto fetch and pull the latest code from git repo

Readme

Git Auto Follow

🚀 An elegant CLI tool for automatically monitoring and pulling the latest code from Git repositories.

✨ Features

  • 🔄 Auto Monitoring: Check remote repository for new commits at fixed intervals
  • 📥 Smart Pulling: Automatically execute git pull when new commits are detected
  • 🎣 Script Hooks: Support for pre-pull and after-pull custom scripts
  • 🔗 Multiple Hook Formats: Hooks can be script files or arrays of commands
  • ⚙️ Flexible Configuration: Customizable check intervals, monitored branches, etc.
  • 🎨 Beautiful Output: Friendly colored terminal output and status indicators
  • 💾 Persistent Config: Configuration automatically saved to local file
  • 📋 CLI Arguments: Support configuration via command line arguments
  • 🔧 Multiple Hook Formats: Support for various naming conventions (camelCase, snake_case, etc.)
  • 🤖 Daemon Mode: Run as a background daemon with automatic log rotation
  • 📝 Log Rotation: Date-based log rotation in .git-auto-follow/logs directory

📦 Installation

npm install -g git-auto-follow

Or use npx to run directly:

npx git-auto-follow

🚀 Quick Start

Run in your Git repository directory:

# Start monitoring directly
npx git-auto-follow

# Or use the full command
npx git-auto-follow start

# Run as daemon with file logging
npx git-auto-follow start --daemon
# or
npx git-auto-follow --daemon

📖 Usage

Basic Commands

# Start monitoring (default command)
git-auto-follow
git-auto-follow start

# Show current status
git-auto-follow status

# Show help
git-auto-follow --help

Command Line Arguments

# Set check interval (30 seconds)
git-auto-follow --interval 30

# Specify hook scripts
git-auto-follow --pre-fetch ./scripts/pre-fetch.sh --after-pull ./scripts/after-pull.sh

# Monitor specific branch
git-auto-follow --branch develop

# Run as daemon with file logging
git-auto-follow --daemon

# Multiple options
git-auto-follow start --interval 60 --branch main --daemon

Available CLI Options

| Option | Description | Example | |--------|-------------|---------| | -i, --interval <number> | Check interval in seconds | --interval 30 | | --pre-fetch <path> | preFetch hook script path | --pre-fetch ./pre-fetch.sh | | --after-fetch <path> | afterFetch hook script path | --after-fetch ./after-fetch.sh | | --pre-pull <path> | prePull hook script path | --pre-pull ./pre-pull.sh | | --after-pull <path> | afterPull hook script path | --after-pull ./after-pull.js | | -b, --branch <name> | Branch to monitor | --branch develop | | -d, --daemon | Run as daemon with file logging | --daemon |

Configuration

You can configure the tool by:

  1. Using CLI arguments (see Available CLI Options above)
  2. Creating a configuration file (see Configuration File section below)
  3. Using default hook scripts (see Hook Scripts section below)

Hook Scripts

Default Hook Discovery

The tool automatically looks for hook scripts in the .git-auto-follow/ directory with these naming patterns:

preFetch hooks (executed before git fetch):

  • preFetch.js, preFetch.mjs, preFetch.ts, preFetch.sh
  • pre_fetch.js, pre_fetch.mjs, pre_fetch.ts, pre_fetch.sh
  • pre-fetch.js, pre-fetch.mjs, pre-fetch.ts, pre-fetch.sh
  • prefetch.js, prefetch.mjs, prefetch.ts, prefetch.sh

afterFetch hooks (executed after git fetch):

  • afterFetch.js, afterFetch.mjs, afterFetch.ts, afterFetch.sh
  • after_fetch.js, after_fetch.mjs, after_fetch.ts, after_fetch.sh
  • after-fetch.js, after-fetch.mjs, after-fetch.ts, after-fetch.sh
  • afterfetch.js, afterfetch.mjs, afterfetch.ts, afterfetch.sh

prePull hooks (executed before git pull):

  • prePull.js, prePull.mjs, prePull.ts, prePull.sh
  • pre_pull.js, pre_pull.mjs, pre_pull.ts, pre_pull.sh
  • pre-pull.js, pre-pull.mjs, pre-pull.ts, pre-pull.sh
  • prepull.js, prepull.mjs, prepull.ts, prepull.sh

afterPull hooks (executed after git pull):

  • afterPull.js, afterPull.mjs, afterPull.ts, afterPull.sh
  • after_pull.js, after_pull.mjs, after_pull.ts, after_pull.sh
  • after-pull.js, after-pull.mjs, after-pull.ts, after-pull.sh
  • afterpull.js, afterpull.mjs, afterpull.ts, afterpull.sh

Example Hook Scripts

prePull Script (.git-auto-follow/prePull.js)
// Stop development server before pulling
const { execSync } = require('node:child_process')

console.log('Preparing to pull latest code...')
try {
  execSync('pkill -f "npm run dev"', { stdio: 'ignore' })
  console.log('Development server stopped')
} catch (error) {
  console.log('No development server to stop')
}
afterPull Script (.git-auto-follow/after_pull.sh)
#!/bin/bash
echo "Code updated, performing post-pull actions..."

# Install new dependencies
npm install

# Restart development server
npm run dev &

echo "Post-pull actions completed"

⚙️ Configuration File

The tool generates a .git-auto-follow.json configuration file in the project root:

{
  "interval": 30,
  "hooks": {
    "preFetch": "./scripts/pre-fetch.sh",
    "afterFetch": "./scripts/after-fetch.sh",
    "prePull": "./scripts/pre-pull.sh",
    "afterPull": "./scripts/after-pull.js"
  },
  "branch": "main",
  "daemon": true
}

Using Command Arrays

You can also specify hooks as arrays of commands instead of script files. Commands will be executed sequentially, and if any command fails, execution stops immediately:

{
  "interval": 30,
  "hooks": {
    "preFetch": [
      "echo 'Fetching updates...'",
      "npm run pre-fetch-check"
    ],
    "prePull": [
      "echo 'Preparing to pull...'",
      "npm run backup",
      "pkill -f 'npm run dev'"
    ],
    "afterPull": [
      "npm install",
      "npm run build",
      "npm run dev &"
    ],
    "afterFetch": [
      "echo 'Fetch completed'",
      "npm run post-fetch-hook"
    ]
  },
  "branch": "main"
}

Configuration Options

| Option | Type | Default | Description | |--------|------|---------|-------------| | interval | number | 30 | Check interval (seconds) | | hooks | object | {} | Hooks configuration object | | hooks.preFetch | string | string[] | - | Hook to run before git fetch | | hooks.afterFetch | string | string[] | - | Hook to run after git fetch | | hooks.prePull | string | string[] | - | Hook to run before git pull | | hooks.afterPull | string | string[] | - | Hook to run after git pull | | branch | string | current branch | Branch name to monitor | | daemon | boolean | false | Run as daemon with file logging |

Configuration Priority

  1. Command line arguments (highest priority)
  2. Configuration file (.git-auto-follow.json)
  3. Default hook scripts (.git-auto-follow/ directory)
  4. Default values (lowest priority)

🤖 Daemon Mode

Run git-auto-follow as a daemon process with automatic file logging:

# Start as daemon
git-auto-follow --daemon

# Or with start command
git-auto-follow start --daemon

Log Rotation

When running in daemon mode, logs are automatically written to .git-auto-follow/logs/ with the following features:

  • Date-based rotation: Each day gets a new log file named YYYY-MM-DD.log
  • Automatic switching: The log file automatically switches at midnight
  • Console + File: All output is shown in console AND written to the log file
  • Clean format: ANSI color codes are stripped from log files for readability

Example log structure:

.git-auto-follow/
├── logs/
│   ├── 2025-01-15.log
│   ├── 2025-01-16.log
│   └── 2025-01-17.log
└── prePull.js

Log file format:

[2025-01-17T10:30:45.123Z] [INFO] 🚀 Starting Git repository monitoring...
[2025-01-17T10:30:45.456Z] [INFO] ⏰ Check interval: 30 seconds
[2025-01-17T10:31:15.789Z] [INFO] 🆕 New commits detected!
[2025-01-17T10:31:16.012Z] [INFO] 📥 Pulling latest code...

🎯 Use Cases

  • Development Environment Sync: Automatically sync latest code during team collaboration
  • Automated Deployment: Simple CI/CD pipeline with custom scripts
  • Code Review: Timely access to code changes for review
  • Multi-environment Sync: Auto-sync main branch changes in testing environments

🛡️ Security Notes

  1. Script Permissions: Ensure pre-pull and after-pull scripts have execution permissions
  2. Conflict Handling: Tool won't automatically handle merge conflicts; will stop pulling on conflicts
  3. Branch Protection: Recommended for use on protected branches to avoid accidental code overwrites
  4. Network Dependency: Requires stable network connection to check remote repository

🔧 Development

# Clone project
git clone <repo-url>
cd git-auto-follow

# Install dependencies
npm install

# Development mode
npm run watch

# Build
npm run build

📝 License

MIT License

🤝 Contributing

Issues and Pull Requests are welcome!

📞 Support

If you encounter problems or have feature suggestions, please submit an Issue.