In the real world, we often work with multiple git repositories in a single project. Changes may span across repositories and multitasking can force us to manage branches across multiple repositories as well. The goal for this project is to make managing changes and branches across multiple repositories easy.
At the moment, it makes assumptions based on my own workspaces: a project single
root with many repositories in a src
folder. If you want to customize this
behavior then you can add a .gitbulkconfig
file. See the Configuration section
below.
git-bulk can be installed through npm.
npm install -g @andreiled/git-bulk
In the directory or directories where you intend to run git bulk
from create a new .gitbulkconfig
file in following format:
module.exports = {
// Either define single root containing all repositories
"repositoryRoot": "./projects"
// Or define each repository explicitly
'repositories': [
// List multiple repositories using just their absolute paths
'./projects/Project1'
// Or define additional properties for some or all of the repositories
{
name: 'ShortName',
path: './projects/LongNameProject',
group: 'front-end' }
]
}
These are the supported operations. It is assumed that git-bulk
will be
executed from the project root. Most of these commands also support targeting subsets
of the repositories as well, which looks like git-bulk status ./src/Repo1 ./src/Repo2 Repo3
.
Repository names can be specified as directory names or paths. For more information on these
commands, run git-bulk help <command>
.
Show the help menu with a list of all possible operations.
Execute git status
on all of the repositories that have any changes, where a
change can be modified files, committed files, or being ahead/behind of the
tracking branch. Names are color coded as well. Repository names will be green
when they have no uncommitted changes and they are ahead of the remote, blue
when there are uncommitted changes, and red when they are behind the remote.
Execute a git fetch
on each of the git repositories. Each repository name will
be printed, along with whether it was successful or not.
Execute a git branch -v
on each of the git repositories.
Execute a git log
on each of the git repositories. This will use a condensed,
custom graph view to display the log for each repo. Optionally pass -n <number>
to change the amount of commits displayed, and -A
to show all branches at once.
Execute a git reset
on each git repository. You can pass a -h
or --hard
switch
as well.
Execute a git checkout
on each git repository. Passing -b branchName
is
mandatory. Passing a -u branchName
option will also set a tracking branch when
creating branches. This will checkout the branch on the target packages, or
create it if it does not exist.
Execute a git rebase
on each git repository. The rebase will only affect
repos with changes, unless the -a
flag is given. If the -i
flag is given,
then rebase will be run in interactive mode. Repo names/paths can also be specified to run
rebase on a subset of repos. The -a flag is still required, even when
specifying repo names manually that have no changes.
Execute an arbitrary shell command specified using the -c
argument on each git repository.
For example, to create a new feature branch in origin
remote using development
branch in upstream
remote:
- on Linux and similar systems:
git bulk exec -c 'git fetch upstream && git push origin upstream/development:refs/heads/feature/%FEATURE_NAME%'
- on Windows with
bash
available (e.g. Git Bash):git bulk exec -c 'bash -c "git fetch upstream && git push origin upstream/development:refs/heads/feature/%FEATURE_NAME%"'