node package manager
It’s your turn. Help us improve JavaScript. Take the 2017 JavaScript Ecosystem Survey »



Create a new branch on-the-fly from your git repo and selectively deploy files to any remote branch.

Getting Started

This plugin requires Grunt ~0.4.1

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-git-selective-deploy --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:


WARNING: This task is "destructive", it means it may alter your working copy. Only run this on your "dest" folder, that is the folder that you intend to deploy to your server. Don't execute this task on your working copy dir unless you know what you are doing. Always test with 'pretend':true before.

The "git_deploy" task


The way this task works is it creates an empty git repository in the src directory you specify, creates an orphan branch and commits all files from that directory to it. Then it pushes the branch to the configured remote repository. Be careful as this destroys the history of the remote branch.. It also creates a .gitignore containing the files/folders you specify, so you can selectively push the filelist.

In your project's Gruntfile.js file, add a section named git_deploy to the data object passed into grunt.initConfig().

  git_deploy: {
    your_target: {
      options: {
        url: '', // the url is read from 
                                                // process.env.GIT_DEPLOY_URL 
                                                // if not specified here 
        pretend: false,   // when true, logs but doesn't perform git commands 
        buildIgnore: true, // then false, does not append or create a .gitignore file 
      src: 'directory/to/deploy', // you may use . for the current directory that Gruntfile.js is 
      dst: './dist/' // if you don't specify this, it WILL ALTER YOUR WORKING COPY 

and execute it from the command line

grunt git_deploy:your_target



Type: String

The URL to a remote git repository. Defaults to the environment variable GIT_DEPLOY_URL, if not specified. The url is required to be present.


Type: String Default value: 'master'

The local branch to create a new branch from.


Type: String Default value: 'master'

The remote branch to push to.


Type: String Default value: 'git deploy'

Commit message. You may use grunt template language <% %> in this message, like to pass in a version for example, automatically.

pkg: grunt.file.readJSON('package.json'),
        message: 'commit v<%= pkg.version %>'


Type: Boolean Default value: true

Set to false to see git results.


Type: Array Default value:


Ignore files on-the-fly to avoid development files to be commited to the server. This will fill new git repo root .gitignore with all the found files and folders.


Type: Boolean Default value: false

Add the --orphan to git checkout command


Type: Boolean Default value: false

Add the --prune to git commit command


Type: Boolean Default value: false

If set to true, will try to merge an existing .gitignore if it exists in src and append the ignored files in it.


Type: Boolean Default value: true

If set to false, no .gitignore file will be written in the created repo (if a .gitignore file already exists, it will not be modified). When this option is false, the ignoreAppend and ignore options have no effect.


Type: Boolean Default value: false

If set to true, this task will log each git command without actually performing it.


Type: Boolean Default value: false

Keeps the dest clone so you can inspect to see if everything is ok


If you can think of a way to unit test this plugin please take a shot at it.