DEV Community

Mahmudur Rahman
Mahmudur Rahman

Posted on

Automating Random Backdated Git Commits with Node.js

Ever wondered how to fill your GitHub contribution graph with meaningful (or fun) commits? Maybe youโ€™re building a Git-based visualizer, running simulations, or just learning how Git automation works.

In this post, Iโ€™ll walk you through a Node.js script that generates random, backdated Git commits between two dates using simple-git, moment, and a few other handy libraries.


GitHub logo mahmud-r-farhan / git-commit-generator

Git Random Commit Generator

๐Ÿ•’ Git Random Commit Generator

This project is a simple Node.js script that creates backdated Git commits with random timestamps between a defined start and end date. It can be useful for:

  • Populating your GitHub contribution graph
  • Testing Git behavior with historical data
  • Learning how to automate Git via Node.js

โš ๏ธ Use responsibly! This script is for educational and testing purposes only.


๐Ÿ“ฆ Features

  • Generates random dates
  • Commits a JSON file (data.json) with each random date as content
  • Commits are made with backdated timestamps using Gitโ€™s --date option
  • Automatically pushes all commits after completion

๐Ÿ“‹ Requirements

  • Node.js (v14+ recommended)
  • Git installed and initialized in your project
  • A remote Git repository set up (for the final push)

๐Ÿ› ๏ธ Setup

  1. Clone this repo or copy the script into your own project
  2. Install dependencies:
npm i
Enter fullscreen mode Exit fullscreen mode

or

npm install jsonfile moment simple-git random
Enter fullscreen mode Exit fullscreen mode
  1. Run the script:
node index.js
Enter fullscreen mode Exit fullscreen mode

You can editโ€ฆ


๐Ÿ”ง What It Does

This script:

  • Generates a random dates.
  • Writes that date into a simple JSON file
  • Commits the file with the --date flag to backdate it
  • Repeats the process for as many times as you want
  • Pushes all commits to your remote repo

Here's the core idea: we're simulating historical commits to test behavior, populate visuals, or automate Git in interesting ways.


๐Ÿ“ฆ Dependencies

npm i
Enter fullscreen mode Exit fullscreen mode

๐Ÿ“ˆ Real-Time Results

Once you run the script, your GitHub contribution graph will start filling up with commits on random days between 2022 and 2025. Itโ€™s fun to visualize and great for testing contribution analytics or dashboards.


โš ๏ธ Use Responsibly

This project is for educational purposes only. Faking contributions to mislead employers or teams is not cool. But if you're doing this for learning, data visualization, or to explore Git automation โ€” go wild!


๐Ÿงช Ideas for Improvement

  • Add CLI arguments to set start/end dates and number of commits
  • Automatically generate different file content for each commit
  • Schedule it via a cron job or GitHub Actions

* Visualize the commit history as a heatmap

Follow for more!

Top comments (0)