NAME
gitbunch - Manage gitbunch directory (directory which contain git repos)
VERSION
This document describes version 0.631 of gitbunch (from Perl distribution Git-Bunch), released on 2024-10-22.
SYNOPSIS
To check the status of bunch (will do a 'git status' for each git repo inside the bunch and report which repos are 'unclean', e.g. needs commit, has untracked files, etc):
% gitbunch check ~/repos
To synchronize bunch to another (will do a 'git pull/push' for each git repo, and do an rsync for everything else):
% gitbunch sync ~/repos /mnt/laptop/repos
DESCRIPTION
A (git)bunch is a directory that contains a bunch of git repositories (as well as dot non-git directories and regular files). This gitbunch utility can help you perform actions on some/all of the repositories in the bunch.
SUBCOMMANDS
check
Check status of git repositories inside gitbunch directory.
Will perform a 'git status' for each git repositories inside the bunch and report which repositories are clean/unclean.
Will die if can't chdir into bunch or git repository.
commit
Commit all uncommitted repos in the bunch.
For each git repository in the bunch, will first check whether the repo is "uncommitted" state, which means either has the status of "Needs commit" or "Has untracked files". The default mode is dry-run/simulation. If the --no-dry-run
flag is not specified, will just show the status of these repos for you. If the --no-dry-run
(can be as short as --no-d
or -N
) flag is specified, will 'git add'+'git commit' all these repos with the same commit message for each, specified in --message
(or just "Committed using 'gitbunch commit'" as the default message).
exec
Execute a command for each repo in the bunch.
For each git repository in the bunch, will chdir to it and execute specified command.
ls
List contents inside gitbunch directory.
Will list each repo or non-repo dir/file.
sync
Synchronize bunch to another bunch.
For each git repository in the bunch, will perform a 'git pull/push' for each branch. If repository in destination doesn't exist, it will be rsync-ed first from source. When 'git pull' fails, will exit to let you fix the problem manually.
For all other non-repo file/directory, will simply synchronize by one-way rsync. But, for added safety, will first check the newest mtime (mtime of the newest file or subdirectory) between source and target is checked first. If target contains the newer newest mtime, rsync-ing for that non-repo file/dir will be aborted. Note: you can use --skip-mtime-check
option to skip this check.
OPTIONS
*
marks required options.
Common options
- --config-path=s, -c
-
Set path to configuration file.
Can actually be specified multiple times to instruct application to read from multiple configuration files (and merge them).
- --config-profile=s, -P
-
Set configuration profile to use.
A single configuration file can contain profiles, i.e. alternative sets of values that can be selected. For example:
[profile=dev] username=foo pass=beaver [profile=production] username=bar pass=honey
When you specify
--config-profile=dev
,username
will be set tofoo
andpassword
tobeaver
. When you specify--config-profile=production
,username
will be set tobar
andpassword
tohoney
. - --debug
-
Shortcut for --log-level=debug.
- --format=s
-
Choose output format, e.g. json, text.
Default value:
undef
Output can be displayed in multiple formats, and a suitable default format is chosen depending on the application and/or whether output destination is interactive terminal (i.e. whether output is piped). This option specifically chooses an output format.
- --help, -h, -?
-
Display help message and exit.
- --json
-
Set output format to json.
- --log-level=s
-
Set log level.
By default, these log levels are available (in order of increasing level of importance, from least important to most):
trace
,debug
,info
,warn
/warning
,error
,fatal
. By default, the level is usually set towarn
, which means that log statements with levelinfo
and less important levels will not be shown. To increase verbosity, chooseinfo
,debug
, ortrace
.For more details on log level and logging, as well as how new logging levels can be defined or existing ones modified, see Log::ger.
- --naked-res
-
When outputing as JSON, strip result envelope.
Default value:
0
By default, when outputing as JSON, the full enveloped result is returned, e.g.:
[200,"OK",[1,2,3],{"func.extra"=>4}]
The reason is so you can get the status (1st element), status message (2nd element) as well as result metadata/extra result (4th element) instead of just the result (3rd element). However, sometimes you want just the result, e.g. when you want to pipe the result for more post-processing. In this case you can use
--naked-res
so you just get:[1,2,3]
- --no-config, -C
-
Do not use any configuration file.
If you specify
--no-config
, the application will not read any configuration file. - --no-env
-
Do not read environment for default options.
If you specify
--no-env
, the application wil not read any environment variable. - --page-result
-
Filter output through a pager.
This option will pipe the output to a specified pager program. If pager program is not specified, a suitable default e.g.
less
is chosen. - --quiet
-
Shortcut for --log-level=error.
- --subcommands
-
List available subcommands.
- --trace
-
Shortcut for --log-level=trace.
- --verbose
-
Shortcut for --log-level=info.
- --version, -v
-
Display program's version and exit.
- --view-result
-
View output using a viewer.
This option will first save the output to a temporary file, then open a viewer program to view the temporary file. If a viewer program is not chosen, a suitable default, e.g. the browser, is chosen.
Options for subcommand check
- --exclude-files
-
Exclude files from processing.
This only applies to
sync_bunch
operations. Operations likecheck_bunch
andexec_bunch
already ignore these and only operate on git repos. - --exclude-non-git-dirs
-
Exclude non-git dirs from processing.
This only applies to and
sync_bunch
operations. Operations likecheck_bunch
andexec_bunch
already ignore these and only operate on git repos. - --exclude-repos-json=s
-
Exclude some repos from processing (JSON-encoded).
See
--exclude-repos
. - --exclude-repos-pat=s
-
Specify regex pattern of repos to exclude.
- --exclude-repos=s@
-
Exclude some repos from processing.
Can be specified multiple times.
- --include-repos-json=s
-
Specific git repos to sync, if not specified all repos in the bunch will be processed (JSON-encoded).
See
--include-repos
. - --include-repos-pat=s
-
Specify regex pattern of repos to include.
- --include-repos=s@
-
Specific git repos to sync, if not specified all repos in the bunch will be processed.
Can be specified multiple times.
- --min-repo-access-time=s
-
Limit to repos that are accessed (mtime, committed, status-ed, pushed) recently.
This can significantly reduce the time to process the bunch if you are only interested in recent repos (which is most of the time unless you are doing a full check/sync).
- --recent
-
Shortcut for --min-repo-access-time="2 weeks ago".
See
--min-repo-access-time
. - --repo=s
-
Only process a single repo.
- --source=s*
-
Directory to check.
Can also be specified as the 1st command-line argument.
- -r
-
Shortcut for --min-repo-access-time="2 weeks ago".
See
--min-repo-access-time
.
Options for subcommand commit
- --command-opts-json=s
-
Options to pass to IPC::System::Options's system() (JSON-encoded).
See
--command-opts
. - --command-opts=s
-
Options to pass to IPC::System::Options's system().
- --exclude-files
-
Exclude files from processing.
This only applies to
sync_bunch
operations. Operations likecheck_bunch
andexec_bunch
already ignore these and only operate on git repos. - --exclude-non-git-dirs
-
Exclude non-git dirs from processing.
This only applies to and
sync_bunch
operations. Operations likecheck_bunch
andexec_bunch
already ignore these and only operate on git repos. - --exclude-repos-json=s
-
Exclude some repos from processing (JSON-encoded).
See
--exclude-repos
. - --exclude-repos-pat=s
-
Specify regex pattern of repos to exclude.
- --exclude-repos=s@
-
Exclude some repos from processing.
Can be specified multiple times.
- --include-repos-json=s
-
Specific git repos to sync, if not specified all repos in the bunch will be processed (JSON-encoded).
See
--include-repos
. - --include-repos-pat=s
-
Specify regex pattern of repos to include.
- --include-repos=s@
-
Specific git repos to sync, if not specified all repos in the bunch will be processed.
Can be specified multiple times.
- --message=s, -m
-
Commit message.
Default value:
"Committed using 'gitbunch commit'"
- --min-repo-access-time=s
-
Limit to repos that are accessed (mtime, committed, status-ed, pushed) recently.
This can significantly reduce the time to process the bunch if you are only interested in recent repos (which is most of the time unless you are doing a full check/sync).
- --recent
-
Shortcut for --min-repo-access-time="2 weeks ago".
See
--min-repo-access-time
. - --repo=s
-
Only process a single repo.
- --source=s*
-
Directory to check.
Can also be specified as the 1st command-line argument.
- -r
-
Shortcut for --min-repo-access-time="2 weeks ago".
See
--min-repo-access-time
.
Options for subcommand exec
- --command-opts-json=s
-
Options to pass to IPC::System::Options's system() (JSON-encoded).
See
--command-opts
. - --command-opts=s
-
Options to pass to IPC::System::Options's system().
- --command=s*
-
Command to execute.
Can also be specified as the 2nd command-line argument and onwards.
- --exclude-files
-
Exclude files from processing.
This only applies to
sync_bunch
operations. Operations likecheck_bunch
andexec_bunch
already ignore these and only operate on git repos. - --exclude-non-git-dirs
-
Exclude non-git dirs from processing.
This only applies to and
sync_bunch
operations. Operations likecheck_bunch
andexec_bunch
already ignore these and only operate on git repos. - --exclude-repos-json=s
-
Exclude some repos from processing (JSON-encoded).
See
--exclude-repos
. - --exclude-repos-pat=s
-
Specify regex pattern of repos to exclude.
- --exclude-repos=s@
-
Exclude some repos from processing.
Can be specified multiple times.
- --include-repos-json=s
-
Specific git repos to sync, if not specified all repos in the bunch will be processed (JSON-encoded).
See
--include-repos
. - --include-repos-pat=s
-
Specify regex pattern of repos to include.
- --include-repos=s@
-
Specific git repos to sync, if not specified all repos in the bunch will be processed.
Can be specified multiple times.
- --min-repo-access-time=s
-
Limit to repos that are accessed (mtime, committed, status-ed, pushed) recently.
This can significantly reduce the time to process the bunch if you are only interested in recent repos (which is most of the time unless you are doing a full check/sync).
- --recent
-
Shortcut for --min-repo-access-time="2 weeks ago".
See
--min-repo-access-time
. - --repo=s
-
Only process a single repo.
- --source=s*
-
Directory to check.
Can also be specified as the 1st command-line argument.
- -r
-
Shortcut for --min-repo-access-time="2 weeks ago".
See
--min-repo-access-time
.
Options for subcommand ls
- --detail, -l
-
Show detailed record for each entry instead of just its name.
- --exclude-files
-
Exclude files from processing.
This only applies to
sync_bunch
operations. Operations likecheck_bunch
andexec_bunch
already ignore these and only operate on git repos. - --exclude-non-git-dirs
-
Exclude non-git dirs from processing.
This only applies to and
sync_bunch
operations. Operations likecheck_bunch
andexec_bunch
already ignore these and only operate on git repos. - --exclude-repos-json=s
-
Exclude some repos from processing (JSON-encoded).
See
--exclude-repos
. - --exclude-repos-pat=s
-
Specify regex pattern of repos to exclude.
- --exclude-repos=s@
-
Exclude some repos from processing.
Can be specified multiple times.
- --include-repos-json=s
-
Specific git repos to sync, if not specified all repos in the bunch will be processed (JSON-encoded).
See
--include-repos
. - --include-repos-pat=s
-
Specify regex pattern of repos to include.
- --include-repos=s@
-
Specific git repos to sync, if not specified all repos in the bunch will be processed.
Can be specified multiple times.
- --min-repo-access-time=s
-
Limit to repos that are accessed (mtime, committed, status-ed, pushed) recently.
This can significantly reduce the time to process the bunch if you are only interested in recent repos (which is most of the time unless you are doing a full check/sync).
- --recent
-
Shortcut for --min-repo-access-time="2 weeks ago".
See
--min-repo-access-time
. - --repo=s
-
Only process a single repo.
- --sort=s
-
Order entries.
Valid values:
["name","-name","mtime","-mtime","commit_time","-commit_time","status_time","-status_time","pull_time","-pull_time"]
- --source=s*
-
Directory to check.
Can also be specified as the 1st command-line argument.
- -r
-
Shortcut for --min-repo-access-time="2 weeks ago".
See
--min-repo-access-time
.
Options for subcommand sync
- --action=s
-
Default value:
"sync"
Valid values:
["sync","list-source-repos"]
- --backup
-
Whether doing backup to target.
This setting lets you express that you want to perform synchronizing to a backup target, and that you do not do work on the target. Thus, you do not care about uncommitted or untracked files/dirs in the target repos (might happen if you also do periodic copying of repos to backup using cp/rsync). When this setting is turned on, the function will first do a
git clean -f -d
(to delete untracked files/dirs) and thengit checkout .
(to discard all uncommitted changes). This setting will also implicitly turn oncreate_bare
setting (unless that setting has been explicitly enabled/disabled). - --create-bare-target, --use-bare
-
Whether to create bare git repo when target does not exist.
When target repo does not exist, gitbunch can either copy the source repo using
rsync
(the default, if this setting is undefined), or it can create target repo withgit init --bare
(if this setting is set to 1), or it can create target repo withgit init
(if this setting is set to 0).Bare git repositories contain only contents of the .git folder inside the directory and no working copies of your source files.
Creating bare repos are apt for backup purposes since they are more space-efficient.
Non-repos will still be copied/rsync-ed.
- --delete-branch
-
Whether to delete branches in dest repos not existing in source repos.
- --exclude-files
-
Exclude files from processing.
This only applies to
sync_bunch
operations. Operations likecheck_bunch
andexec_bunch
already ignore these and only operate on git repos. - --exclude-non-git-dirs
-
Exclude non-git dirs from processing.
This only applies to and
sync_bunch
operations. Operations likecheck_bunch
andexec_bunch
already ignore these and only operate on git repos. - --exclude-repos-json=s
-
Exclude some repos from processing (JSON-encoded).
See
--exclude-repos
. - --exclude-repos-pat=s
-
Specify regex pattern of repos to exclude.
- --exclude-repos=s@
-
Exclude some repos from processing.
Can be specified multiple times.
- --include-repos-json=s
-
Specific git repos to sync, if not specified all repos in the bunch will be processed (JSON-encoded).
See
--include-repos
. - --include-repos-pat=s
-
Specify regex pattern of repos to include.
- --include-repos=s@
-
Specific git repos to sync, if not specified all repos in the bunch will be processed.
Can be specified multiple times.
- --min-repo-access-time=s
-
Limit to repos that are accessed (mtime, committed, status-ed, pushed) recently.
This can significantly reduce the time to process the bunch if you are only interested in recent repos (which is most of the time unless you are doing a full check/sync).
- --recent
-
Shortcut for --min-repo-access-time="2 weeks ago".
See
--min-repo-access-time
. - --repo=s
-
Only process a single repo.
- --rsync-del
-
Whether to use --del rsync option.
When rsync-ing non-repos, by default
--del
option is not used for more safety because rsync is a one-way action. To add rsync--del
option, enable this - --rsync-opt-maintain-ownership
-
Whether or not, when rsync-ing from source, we use -a (= -rlptgoD) or -rlptD (-a minus -go).
Sometimes using -a results in failure to preserve permission modes on sshfs-mounted filesystem, while -rlptD succeeds, so by default we don't maintain ownership. If you need to maintain ownership (e.g. you run as root and the repos are not owned by root), turn this option on.
- --skip-mtime-check, -M
-
Whether or not, when rsync-ing non-repos, we check mtime first.
By default when we rsync a non-repo file/dir from source to target and both exist, to protect wrong direction of sync-ing we find the newest mtime in source or dir (if dir, then the dir is recursively traversed to find the file/subdir with the newest mtime). If target contains the newer mtime, the sync for that non-repo file/dir is aborted. If you want to force the rsync anyway, use this option.
- --source=s*
-
Directory to check.
Can also be specified as the 1st command-line argument.
- --target=s*
-
Destination bunch.
Can also be specified as the 2nd command-line argument.
- -r
-
Shortcut for --min-repo-access-time="2 weeks ago".
See
--min-repo-access-time
.
COMPLETION
This script has shell tab completion capability with support for several shells.
bash
To activate bash completion for this script, put:
complete -C gitbunch gitbunch
in your bash startup (e.g. ~/.bashrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.
It is recommended, however, that you install modules using cpanm-shcompgen which can activate shell completion for scripts immediately.
tcsh
To activate tcsh completion for this script, put:
complete gitbunch 'p/*/`gitbunch`/'
in your tcsh startup (e.g. ~/.tcshrc). Your next shell session will then recognize tab completion for the command. Or, you can also directly execute the line above in your shell to activate immediately.
It is also recommended to install shcompgen (see above).
other shells
For fish and zsh, install shcompgen as described above.
CONFIGURATION FILE
This script can read configuration files. Configuration files are in the format of IOD, which is basically INI with some extra features.
By default, these names are searched for configuration filenames (can be changed using --config-path
): /home/u1/.config/gitbunch.conf, /home/u1/gitbunch.conf, or /etc/gitbunch.conf.
All found files will be read and merged.
To disable searching for configuration files, pass --no-config
.
To put configuration for a certain subcommand only, use a section name like [subcommand=NAME]
or [SOMESECTION subcommand=NAME]
.
You can put multiple profiles in a single file by using section names like [profile=SOMENAME]
or [SOMESECTION profile=SOMENAME]
or [subcommand=SUBCOMMAND_NAME profile=SOMENAME]
or [SOMESECTION subcommand=SUBCOMMAND_NAME profile=SOMENAME]
. Those sections will only be read if you specify the matching --config-profile SOMENAME
.
You can also put configuration for multiple programs inside a single file, and use filter program=NAME
in section names, e.g. [program=NAME ...]
or [SOMESECTION program=NAME]
. The section will then only be used when the reading program matches.
You can also filter a section by environment variable using the filter env=CONDITION
in section names. For example if you only want a section to be read if a certain environment variable is true: [env=SOMEVAR ...]
or [SOMESECTION env=SOMEVAR ...]
. If you only want a section to be read when the value of an environment variable equals some string: [env=HOSTNAME=blink ...]
or [SOMESECTION env=HOSTNAME=blink ...]
. If you only want a section to be read when the value of an environment variable does not equal some string: [env=HOSTNAME!=blink ...]
or [SOMESECTION env=HOSTNAME!=blink ...]
. If you only want a section to be read when the value of an environment variable includes some string: [env=HOSTNAME*=server ...]
or [SOMESECTION env=HOSTNAME*=server ...]
. If you only want a section to be read when the value of an environment variable does not include some string: [env=HOSTNAME!*=server ...]
or [SOMESECTION env=HOSTNAME!*=server ...]
. Note that currently due to simplistic parsing, there must not be any whitespace in the value being compared because it marks the beginning of a new section filter or section name.
To load and configure plugins, you can use either the -plugins
parameter (e.g. -plugins=DumpArgs
or -plugins=DumpArgs@before_validate_args
), or use the [plugin=NAME ...]
sections, for example:
[plugin=DumpArgs]
-event=before_validate_args
-prio=99
[plugin=Foo]
-event=after_validate_args
arg1=val1
arg2=val2
which is equivalent to setting -plugins=-DumpArgs@before_validate_args@99,-Foo@after_validate_args,arg1,val1,arg2,val2
.
List of available configuration parameters:
Common for all subcommands
Configuration for subcommand check
exclude_files (see --exclude-files)
exclude_non_git_dirs (see --exclude-non-git-dirs)
exclude_repos (see --exclude-repos)
exclude_repos_pat (see --exclude-repos-pat)
include_repos (see --include-repos)
include_repos_pat (see --include-repos-pat)
min_repo_access_time (see --min-repo-access-time)
repo (see --repo)
source (see --source)
Configuration for subcommand commit
command_opts (see --command-opts)
exclude_files (see --exclude-files)
exclude_non_git_dirs (see --exclude-non-git-dirs)
exclude_repos (see --exclude-repos)
exclude_repos_pat (see --exclude-repos-pat)
include_repos (see --include-repos)
include_repos_pat (see --include-repos-pat)
message (see --message)
min_repo_access_time (see --min-repo-access-time)
repo (see --repo)
source (see --source)
Configuration for subcommand exec
command (see --command)
command_opts (see --command-opts)
exclude_files (see --exclude-files)
exclude_non_git_dirs (see --exclude-non-git-dirs)
exclude_repos (see --exclude-repos)
exclude_repos_pat (see --exclude-repos-pat)
include_repos (see --include-repos)
include_repos_pat (see --include-repos-pat)
min_repo_access_time (see --min-repo-access-time)
repo (see --repo)
source (see --source)
Configuration for subcommand ls
detail (see --detail)
exclude_files (see --exclude-files)
exclude_non_git_dirs (see --exclude-non-git-dirs)
exclude_repos (see --exclude-repos)
exclude_repos_pat (see --exclude-repos-pat)
include_repos (see --include-repos)
include_repos_pat (see --include-repos-pat)
min_repo_access_time (see --min-repo-access-time)
repo (see --repo)
sort (see --sort)
source (see --source)
Configuration for subcommand sync
action (see --action)
backup (see --backup)
create_bare_target (see --create-bare-target)
delete_branch (see --delete-branch)
exclude_files (see --exclude-files)
exclude_non_git_dirs (see --exclude-non-git-dirs)
exclude_repos (see --exclude-repos)
exclude_repos_pat (see --exclude-repos-pat)
include_repos (see --include-repos)
include_repos_pat (see --include-repos-pat)
min_repo_access_time (see --min-repo-access-time)
repo (see --repo)
rsync_del (see --rsync-del)
rsync_opt_maintain_ownership (see --rsync-opt-maintain-ownership)
skip_mtime_check (see --skip-mtime-check)
source (see --source)
target (see --target)
ENVIRONMENT
GITBUNCH_OPT
String. Specify additional command-line options.
FILES
/home/u1/.config/gitbunch.conf
/home/u1/gitbunch.conf
/etc/gitbunch.conf
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/Git-Bunch.
SOURCE
Source repository is at https://github.com/perlancar/perl-Git-Bunch.
SEE ALSO
http://joeyh.name/code/mr/. You probably want to use this instead. mr supports other control version software aside from git, doesn't restrict you to put all your repos in one directory, supports more operations, and has been developed since 2007. Had I known about mr, I probably wouldn't have started gitbunch. On the other hand, gitbunch is simpler (I think), doesn't require any config file, and can copy/sync files/directories not under source control. I mainly use gitbunch to quickly: 1) check whether there are any of my repositories which have uncommitted changes; 2) synchronize (pull/push) to other locations. I put all my data in one big gitbunch directory; I find it simpler. gitbunch works for me and I use it daily.
Other tools on CPAN to make it easier to manage multiple git repositories: got from App::GitGot, group-git from Group::Git.
AUTHOR
perlancar <perlancar@cpan.org>
CONTRIBUTING
To contribute, you can send patches by email/via RT, or send pull requests on GitHub.
Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.
COPYRIGHT AND LICENSE
This software is copyright (c) 2024 by perlancar <perlancar@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=Git-Bunch
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.