Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
G

git-xargs

> 开发工具
Open source

git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command.

1.1K stars0 likes0 views
WebsiteGitHub

About

git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command.

Table of contents

  • Introduction
  • Reference
  • Contributing

Introduction

Overview

git-xargs is a command-line tool (CLI) for making updates across multiple GitHub repositories with a single command. You give git-xargs:

  1. a script or a command to run
  2. a list of repos

and git-xargs will:

  1. clone each repo
  2. run your specified script or command against it
  3. commit any changes
  4. open pull requests
  5. provide a detailed report of everything that happened

Git-xargs leverages goroutines to perform the repo-updating work in parallel, so it is very fast.

For example, have you ever needed to add a particular file across many repos at once? Or to run a search and replace to change your company or product name across 150 repos with one command? What about upgrading Terraform modules to all use the latest syntax? How about adding a CI/CD configuration file, if it doesn't already exist, or modifying it in place if it does, but only on a subset of repositories you select? You can handle these use cases and many more with a single git-xargs command.

Example: writing a new file to every repo in your GitHub organization

As an example, let's use git-xargs to create a new file in every repo:

bash
git-xargs \
  --branch-name test-branch \
  --github-org  \
  --commit-message "Create hello-world.txt" \
  touch hello-world.txt

Here's what it looks like in action:

In this example, every repo in your org will have a new file named hello-world.txt written to it with the contents "Hello, World!". You'll then receive an easy-to-read printout of exactly what happened on STDOUT:

…

Getting started

Installation option 1: Homebrew

If you are Homebrew user, you can install by running

bash
$ brew install git-xargs

Installation option 2: Installing published binaries

  1. Download the correct binary for your platform. Visit the releases page and download the correct binary depending on your system. Save it to somewhere on your PATH, such as /usr/local/bin/git-xargs.

  2. Set execute permissions. For example, on Linux or Mac, you'd run:

    bash
    chmod u+x /usr/local/bin/git-xargs
  3. Check it's working. Run the version command to ensure everything is working properly:

    bash
    git-xargs --version

Installation option 3: Run go install or go get

  1. Ensure you have Golang installed and working properly on your system. Follow the official Golang install guide to get started.

  2. Run go install to install the latest release of git-xargs:

    bash
    go install github.com/gruntwork-io/git-xargs@latest
  3. Alternatively, use go install to select a specific release of git-xargs:

    bash
    go install github.com/gruntwork-io/[email protected]
  4. If you have Go 1.16 or earlier, you can use get

    bash
    go get github.com/gruntwork-io/git-xargs
    go get github.com/gruntwork-io/[email protected]

Try it out!

  1. Export a valid GitHub token. See the guide on Github personal access tokens for information on how to generate one. For example, on Linux or Mac, you'd run:

    bash
    export GITHUB_OAUTH_TOKEN=
  2. Setup authentication with your Github Enterprise server. To use a Github Enterprise server, set the GITHUB_HOSTNAME environment variable:

    bash
    export GITHUB_HOSTNAME=
  3. Provide a script or command and target some repos. Here's a simple example of running the touch command in every repo in your GitHub organization. Follow the same pattern to start running your own scripts and commands against your own repos!

    bash
    git-xargs \
      --branch-name "test-branch" \
      --commit-message "Testing git-xargs" \
      --github-org  \
      touch git-xargs-is-awesome.txt

Reference

How to supply commands or scripts to run

The API for git-xargs is:

git-xargs [-flags] 

Where CMD is either the full path to a (Bash, Python, Ruby, etc) script on your local system or a binary. Note that, because the tool supports Bash scripts, Ruby scripts, Python scripts, etc, you must include the full filename for any given script, including its file extension.

In other words, all the following usages are valid:

bash
git-xargs --repo gruntwork-io/cloud-nuke \
   --repo gruntwork-io/terraform-aws-eks \
   --branch-name my-branch \
   /usr/local/bin/my-bash-script.sh
bash
git-xargs --repos ./my-repos.txt \
  --branch-name my-other-branch \
  touch file1.txt file2.txt
bash
git-xargs --github-org my-github-org \
  --branch-name my-new-branch \
  "$(pwd)/scripts/my-ruby-script.rb"

Using git-xargs environment variables in commands or scripts

When executing commands or scripts, git-xargs will register the following environment variables for use by commands or scripts based on the arguments and flags provided:

Env var Value
XARGS_DRY_RUN Whether the --dry-run flag was provided to git-xargs; options are true, false
XARGS_REPO_NAME Name of the target repository being processed
XARGS_REPO_OWNER Owner of the target repository being processed

Debugging runtime errors

By default, git-xargs will conceal runtime errors as they occur because its log level setting is INFO if not overridden by the --loglevel flag.

To see all errors your script or command may be generating, be sure to pass --loglevel DEBUG when running your git-xargs command, like so:

bash
git-xargs --loglevel DEBUG \
	--repo zack-test-org/terraform-aws-eks \
	--branch-name master \
	--commit-message "add blank file" \
	--skip-pull-requests touch foo.txt

When the log level is set to debug you should see new error output similar to the following:

Total 195 (delta 159), reused 27 (delta 11), pack-reused 17  Repo=terraform-aws-eks
[git-xargs] DEBU[2021-06-29T12:11:31-04:00] Created branch                                Branc
h Name=refs/heads/master Repo=terraform-aws-eks
[git-xargs] DEBU[2021-06-29T12:11:31-04:00] Error creating new branch                     Error
="a branch named \"refs/heads/master\" already exists" Repo=terraform-aws-eks
[git-xargs] DEBU[2021-06-29T12:11:31-04:00] Error encountered while processing repo       Error
="a branch named \"refs/heads/master\" already exists" Repo name=terraform-aws-eks

Rate Limiting

git-xargs attempts to be a good citizen as regards consumption of the GitHub API. git-xargs conforms to GitHub's API integration guidelines.

In addition, git-xargs includes several features and flags to help you:

  1. run jobs without tripping GitHub's rate limits
  2. recover when rate limited by automatically retrying failed pull requests again, all while honoring the GitHub rate limits

Distinct processing channels for expensive and non-expensive work

git-xargs distinguishes between work that is safe to perform in parallel, such as certain git operations, and work that must be done with consideration of resource constraints, such as issuing open pull requests to GitHub's API. Therefore, git-xargs is able to perform all concurrency-safe work as quickly as possible by leveraging goroutines, while treating the more expensive open pull request API calls separately.

Pull requests are handled on a separate channel so that they can be buffered and retried in accordance with rate limiting feedback git-xargs is receiving from GitHub's API.

This means that git-xargs performs all the work upfront that it can as quickly as possible, and then moves on to serially process the pull request jobs that have resulted from the concurrency-safe work of cloning repositories, making file changes, checking the git worktree, etc.

Limit amount of parallel git clones

GitHub has a rate limiting on GitHub clones. Which is why per default only 4 clones happen in parallel. This setting can be adjusted with the --max-concurrent-clones flag. Setting it to 0 or lower means no limit is applied.

Automatic pull request retries when rate limited

By default, git-xargs will re-attempt opening a pull request that failed due to rate limiting. The --max-pr-retries flag allows you to specify how many times you'd like a given pull request to be re-attempted in case of failure due to rate limiting. By default, the value is 3, meaning that if you do not pass this flag, git-xargs will retry all rate-limit-blocked pull requests 3 times.

Automatic backoff when rate limiting is detected

When git-xargs detects that it has been rate limited by GitHub, it begins requeuing failed pull requests for retry, but with an additional, larger buffer of time in between the next attempt. This larger buffer of time is intended to allow GitHub rate limit status to return to baseline for the git-xargs client. The --seconds-to-wait-when-ratelimited flag specifies the number of seconds to wait when git-xargs detects it has been rate limited. Note that this extra buffer of time is in addition to the value specified by the --seconds-between-prs flag.

When they are provided by GitHub, git-xargs will instead use the values of any Retry-After header, or the delta of seconds between the current time and the rate limit error's reset time. When these two values are not available, git-xargs falls back to the user-specified value of --seconds-to-wait-when-ratelimited, if the flag was passed, or the default value, which is 60 seconds.

Specifying the pause between pull requests

The GitHub's API integration guidelines specify that clients should pause at least 1 second in between consecutive requests against expensive endpoints, such as the one for opening a new pull request. As a result, git-xargs defaults to pausing 1 second in between each pull request that is opened. The flag --seconds-between-prs allows you to modify this value. For example, if you were to pass --seconds-between-prs 30, then git-xargs will sleep for half a minute between issuing pull request API calls to GitHub.

Guidelines and observations from testing

In local testing, the actual thresholds for when GitHub's secondary rate limits kick in can vary depending on the number of repos you're targeting and how long your script or command takes to complete. Secondary rate limits have been observed on jobs targeting as few as 10 repositories. If you are using the rate limiting flags with reasonable values, your job should never be rate-limited in the first place.

If your job is consistently being rate-limited, try incrementally increasing the value you pass with the --seconds-between-prs flag. Passing a higher value will increase the overall time your job takes to complete, but it will also greatly decrease the likelihood of your job tripping GitHub's rate limits at all. Passing a lower value, or not passing the flag at all, will greatly increase the likelihood that your job is rate limited by GitHub.

Branch behavior

Passing the --branch-name (-b) flag is required when running git-xargs. If you specify the name of a branch that exists on your remote, its latest changes will be pulled locally prior to your command or script being run. If you specify the name of a new branch that does not yet exist

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Goautomationcligitgolang

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category开发工具
PricingOpen source

> Related tools

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