git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command.
git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command.
git-xargs is a command-line tool (CLI) for making updates across multiple GitHub repositories with a single command. You give git-xargs:
and git-xargs will:
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.
As an example, let's use git-xargs to create a new file in every repo:
git-xargs \
--branch-name test-branch \
--github-org \
--commit-message "Create hello-world.txt" \
touch hello-world.txtHere'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:
…If you are Homebrew user, you can install by running
$ brew install git-xargsDownload 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.
Set execute permissions. For example, on Linux or Mac, you'd run:
chmod u+x /usr/local/bin/git-xargsCheck it's working. Run the version command to ensure everything is working properly:
git-xargs --versionEnsure you have Golang installed and working properly on your system. Follow the official Golang install guide to get started.
Run go install to install the latest release of git-xargs:
go install github.com/gruntwork-io/git-xargs@latestAlternatively, use go install to select a specific release of git-xargs:
go install github.com/gruntwork-io/[email protected]If you have Go 1.16 or earlier, you can use get
go get github.com/gruntwork-io/git-xargs
go get github.com/gruntwork-io/[email protected]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:
export GITHUB_OAUTH_TOKEN=Setup authentication with your Github Enterprise server. To use a Github Enterprise server, set the GITHUB_HOSTNAME environment variable:
export GITHUB_HOSTNAME=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!
git-xargs \
--branch-name "test-branch" \
--commit-message "Testing git-xargs" \
--github-org \
touch git-xargs-is-awesome.txtThe 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:
git-xargs --repo gruntwork-io/cloud-nuke \
--repo gruntwork-io/terraform-aws-eks \
--branch-name my-branch \
/usr/local/bin/my-bash-script.shgit-xargs --repos ./my-repos.txt \
--branch-name my-other-branch \
touch file1.txt file2.txtgit-xargs --github-org my-github-org \
--branch-name my-new-branch \
"$(pwd)/scripts/my-ruby-script.rb"git-xargs environment variables in commands or scriptsWhen 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 |
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:
git-xargs --loglevel DEBUG \
--repo zack-test-org/terraform-aws-eks \
--branch-name master \
--commit-message "add blank file" \
--skip-pull-requests touch foo.txtWhen 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
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:
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.
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
No open issues yet, or sync has not completed.