---
title: "Grunt Tweet Git Commit"
description: "Automatically tweet about every git commit using Grunt. Practical notes and code examples on Grunt Tweet Git Commit by in JS."
url: "https://h3manth.com/scribe/grunt-tweet-git-commit/"
canonical_url: "https://h3manth.com/scribe/grunt-tweet-git-commit/"
markdown_url: "https://h3manth.com/scribe/blog/grunt-tweet-git-commit.md"
publishDate: "2013-07-07T00:00:00.000Z"
author: "Hemanth HM"
category: "node"
tags: ["node","grunt","git","cli"]
word_count: 140
reading_time_minutes: 1
x_markdown_tokens: 382
content_signal: "ai-train=yes, search=yes, ai-input=yes"
---

# Grunt Tweet Git Commit

> Automatically tweet about every git commit using Grunt. Practical notes and code examples on Grunt Tweet Git Commit by in JS.

A fun CLI hack to automatically tweet about every git commit.

## Prerequisites

npm install ntwitter
npm install -g grunt-cli

## Custom Grunt Tweet Task

```javascript
grunt.registerTask('tweet', 'Tweet the commit info', function() {
  var twitter = require('twitter');
  var shell = require('shelljs');
  
  var commit_comment = shell.exec('git log -1 --pretty=%B').output
    .replace(/(\r\n|\n|\r)/gm, '');
  var repo = shell.exec('basename $(git remote show -n origin | grep Fetch | cut -d: -f2-)').output
    .replace(/(\r\n|\n|\r)/gm, '');
  var author = shell.exec("git --no-pager show -s --format='%an'").output
    .replace(/(\r\n|\n|\r)/gm, '');
  
  var tweet = util.format('%s on %s by %s', commit_comment, repo, author);
  
  var twit = new twitter({
    consumer_key: 'Twitter',
    consumer_secret: 'API',
    access_token_key: 'keys',
    access_token_secret: 'go here'
  });
  
  twit.updateStatus(tweet, function(err, data) {
    console.log(data);
  });
});
```

Have a pre-commit hook at `.git/hooks/pre-commit` calling `grunt tweet` to tweet on every commit!

The tweet would be something like: `'jshint suggestions from @passy on yo.git by Hemanth.HM'`
