百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
G

gulp-git

> 开发工具
开源

用于 gulp 的 Git 插件 (gulpjs.com)

399 stars0 点赞3 次浏览
访问官网GitHub

工具介绍

用于 gulp 的 Git 插件 (gulpjs.com)

gulp-git

Packagegulp-git

Description Git plugin for gulp (gulpjs.com)

Node Version

= 0.9

Gulp Version 3.x

Usage

Install

bash
npm install gulp-git --save

0.4.0 introduced Breaking Changes!

Git actions which did not require a Vinyl file were refactored. Please review the following docs for changes: ##Example

…

##API

git.init(opt, cb)

git init

Creates an empty git repo

opt: Object (optional) {args: 'options', cwd: '/cwd/path', quiet: true, maxBuffer: 200 * 1024}

cb: function, passed err if any

javascript
git.init({args:'options'}, function (err) {
  //if (err) ...
});

git.clone(remote, opt, cb)

git clone

Clones a remote repo for the first time

remote: String, remote url

opt: Object (optional) {args: 'options', cwd: '/cwd/path', quiet: true, maxBuffer: 200 * 1024}

cb: function, passed err if any

javascript
git.clone('https://remote.git', function (err) {
  //if (err) ...
});

A desination folder or subfolder can be set with args: ''

git.clone('https://remote.git', {args: './sub/folder'}, function (err) {
  //if (err) ...
});

git.add(opt)

git add

Adds files to repo

opt: Object (optional) {args: 'options', cwd: '/cwd/path', quiet: true, maxBuffer: 200 * 1024, maxFiles: Infinity}

javascript
gulp.src('./*')
  .pipe(git.add());
});

git.commit(message, opt)

git commit -m

Commits changes to repo

message: String or array of strings, commit message

opt: Object (optional) {args: 'options', cwd: '/cwd/path', maxBuffer: 200 * 1024, quiet: true, disableMessageRequirement: false, disableAppendPaths: false, multiline: false}

javascript
gulp.src('./*')
  .pipe(git.commit('commit message'));
});

git.addRemote(remote, url, opt, cb)

git remote add

Adds remote repo url

remote: String, name of remote, default: origin

url: String, url of remote

opt: Object (optional) {args: 'options', cwd: '/cwd/path', quiet: true, maxBuffer: 200 * 1024}

cb: function, passed err if any

javascript
git.addRemote('origin', 'git-repo-url', function (err) {
  //if (err) ...
});

git.removeRemote(remote, opt, cb)

git remote remove

Removes remote repo

remote: String, name of remote

opt: Object (optional) {args: 'options', cwd: '/cwd/path', quiet: true, maxBuffer: 200 * 1024}

cb: function, passed err if any

javascript
git.removeRemote('origin', function (err) {
  //if (err) ...
});

git.fetch(remote, branch, opt, cb)

git fetch

Fetches refs and objects from remote repo

remote: String, name of remote, default: origin

branch: String, branch, default: ``

opt: Object (optional) {args: 'options', cwd: '/cwd/path', quiet: true, maxBuffer: 200 * 1024}

cb: function, passed err if any

javascript
git.fetch('origin', '', function (err) {
  //if (err) ...
});

git.pull(remote, branch, opt, cb)

git pull

Pulls changes from remote repo

remote: String, name of remote, default: undefined

branch: String || Array, branch, default: undefined

opt: Object (optional) {args: 'options', cwd: '/cwd/path', quiet: true, maxBuffer: 200 * 1024}

cb: function, passed err if any

javascript
git.pull('origin', 'master', function (err) {
  //if (err) ...
});

// without any remote or branches
git.pull(function(err){
  //if (err) ...
});

// with only a remote
git.pull('upstream', function(err){
  //if (err) ...
});

// with remote and an array of branches
git.pull('upstream' ['dev', 'master'], function(err){
  //if (err) ...
});

git.push(remote, branch, opt, cb)

git push

Pushes changes to remote repo

remote: String, name of remote, default: origin

branch: String (may be null), branch, default: master

opt: Object (optional) {args: 'options', cwd: '/cwd/path', quiet: true}

cb: function, passed err if any

javascript
git.push('origin', 'master', function (err) {
  //if (err) ...
});

git.tag(version, message, opt, cb)

git tag -a/s -m

Tags repo with release version, returns all tags when used without arguments

version: String (optional), tag name

message: String or array of strings (optional), tag message

opt: Object (optional) {args: 'options', cwd: '/cwd/path', quiet: true, maxBuffer: 200 * 1024}

cb: function, passed err if any

javascript
git.tag('v1.1.1', 'Version message', function (err) {
  //if (err) ...
});

if options.signed is set to true, the tag will use the git secure key: git.tag('v1.1.1', 'Version message with signed key', {signed: true});

git.branch(branch, opt, cb)

git branch

Creates a new branch but doesn't switch to it

(Want to switch as you create? Use git.checkout({args:'-b'}).)

branch: String, branch

opt: Object (optional) {args: 'options', cwd: '/cwd/path', quiet: true, maxBuffer: 200 * 1024}

cb: function, passed err if any

javascript
git.branch('development', function (err) {
  //if (err) ...
});

git.showBranch(opt, cb)

git show-branch

Show branches and their commits

opt: Object (optional) {args: 'options'}

cb: function, passed err if any

javascript
git.showBranch({'args': '--list -a'}, function (err) {
  //if (err) ...
});

git.checkout(branch, opt, cb)

git checkout

Checkout a new branch with files

branch: String, branch

opt: Object (optional) {args: 'options', cwd: '/cwd/path', quiet: true, maxBuffer: 200 * 1024}

cb: function, passed err if any

javascript
git.checkout('development', function (err) {
  //if (err) ...
});

If you want to create a branch and switch to it:

javascript
git.checkout('development', {args:'-b'}, function (err) {
  //if (err) ...
});

If you want to checkout files (e.g. revert them) use git.checkoutFiles:

javascript
gulp.src('./*')
  .pipe(git.checkoutFiles());

git.checkoutFiles(opt)

git checkout

Checkout (e.g. reset) files

opt: Object (optional) {args: 'options', quiet: true, maxBuffer: 200 * 1024}

javascript
gulp.src('./*')
  .pipe(git.checkoutFiles());

git.merge(branch, opt, cb)

git merge

Merges a branch into the current branch

branch: String, source branch

opt: Object (optional) {args: 'options', cwd: '/cwd/path', quiet: true, maxBuffer: 200 * 1024}

cb: function, passed err if any

javascript
git.merge('development', function (err) {
  //if (err) ...
});

git.rm()

git rm

Removes a file from git and deletes it

opt: Object (optional) {args: 'options', quiet: true, maxBuffer: 200 * 1024}

javascript
gulp.src('./*')
  .pipe(git.commit('commit message'));
});

git.reset(commit, opt, cb)

git reset

Resets working directory to specified commit hash

commit: String, commit hash or reference

opt: Object (optional) {args: 'options', cwd: '/cwd/path', quiet: true, maxBuffer: 200 * 1024}

cb: function, passed err if any

javascript
git.reset('HEAD' {args:'--hard'}, function (err) {
  //if (err) ...
});

git.revParse(opt, cb)

git rev-parse

Get details about the repository

opt: Object (optional) {args: 'options', cwd: '/cwd/path', quiet: true, maxBuffer: 200 * 1024}

cb: function, passed err if any and command stdout

javascript
git.revParse({args:'--short HEAD'}, function (err, hash) {
  //if (err) ...
  console.log('current git hash: '+hash);
});

git.addSubmodule()

git submodule add

Options: Object

.addSubmodule('https://repository.git', 'path', {args: "options", quiet: true})

git.updateSubmodule()

git submodule update

Options: Object

.updateSubmodule({args: "options", quiet: true})

git.status(opt, cb)

git status

Show the working tree status

opt: Object (optional) {args: 'options', cwd: '/cwd/path', maxBuffer: 200 * 1024, quiet: true}

cb: function (optional), passed err and command stdout

javascript
git.status({args : '--porcelain'}, function (err, stdout) {
  // if (err) ...
});

git.exec(opt, cb)

git

Run other git actions that do not require a Vinyl.

opt: Object (optional) {args: 'options', cwd: '/cwd/path', maxBuffer: 200 * 1024, quiet: true}

cb: function (optional), passed err and command stdout

javascript
git.exec({args : 'log --follow index.js'}, function (err, stdout) {
  //if (err) ...
});

git.clean(paths, opt, cb)

git clean

Remove untracked files from the working tree

paths: String (optional), paths to be affected by clean operation

opt: Object (optional), {args: 'options', cwd: '/cwd/path', quiet: true, maxBuffer: 200 * 1024}

cb: function (optional), passed err if any

git.diff(branch, opt)

git diff master

Diffs between git objects

branch: String, branch name, commit name, or git tag

opt: Object (optional) {args: 'options', cwd: '/cwd/path', quiet: true, maxBuffer: 200 * 1024}

javascript
gulp.task('diff', function(){
  gulp.src('./*')
    .pipe(git.diff('develop', {log: true}))
    .pipe(gulp.dest('./diff.out'));
});

You can view more examples in the example folder.

Possible errors:

stdout maxBuffer exceeded

Reported here.

If you get this error it means that the git process doesn't have enough memory.

Every function has an additional option: maxBuffer.

javascript
gulp.task('pull', function(){
  git.pull('origin', 'master', {args: '--rebase', maxBuffer: Infinity}, function (err) {
    if (err) throw err;
  });
});

The command line is too long.

Reported here.

If the git add command exceeds 8191 characters on Windows you will get this error.

The add function has an additional option: maxFiles.

javascript
gulp.task('add', function(){
  return gulp.src('./git-test/*')
    .pipe(git.add({maxFiles: 8}));
});

LICENSE

(MIT License)

Copyright (c) 2015 Steve Lacy slacy.me

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Issues· 1 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

JavaScriptgitgulp

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类开发工具
定价开源

> 相关工具

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具