MyGit - Bash Git Automation Script
Migrated all my ZSH git functions into a standalone bash script.
go-mygit replaced this project.
Who & Why
- Creating repositories for same set of remote servers repeatedly
- Setting up repositories on multiple machines repeatedly
- Working with repositories that push to same set of git servers
- Git Base Commands
- API Base Commands
- Strict option/argument order
- Minimum command line error detection
- Current supported git servers
- API commands must be executed at root of repository
Following configuration will be used in all examples:
Example below can be tested inside
Use following to enable debug output:
group command provide a quick way to see what is configured.
To show all
To show all
mygit allow command applied to groups or remotes through the use of
-r/--remote. This applies to all commands except
group mentioned above.
-r/--remote must be placed right after
mygit and before any command.
-r/--remote can be used at the same time.
Git Base Commands
push are git base commands.
mygit init will clear all existing remote and add remote base on
-r selector. If no group nor remote are specified, all configured remotes will be added.
mygit init by default use current directory name as repository name. Repository name can be specified in the format
mygit init <repository>. File
.mygit containing the repository name will be created, which is used by API based commands.
mygit init without selector:
mygit init with group internal:
mygit init with repository name:
mygit push will do
git push and
git push --tag base on
-r selector. If no group nor remote are specified, all configured remotes will be pushed in sequence.
mygit push support options
--master is used,
mygit push will push to upstream(
-u) master branch.
--all is used,
mygit push will push all branches(
fetch will do
git fetch base on
-r selector. If no group nor remote are specified, all configured remotes will be fetched in sequence.
API Repo Commands
mygit repo <command> are API base command. With exception of
mygit repo ls/list, all API commands must be ran at root of repository.
mygit repo without specifying additional command will retrieve repository information from remote server.
--public are options for
repo new and
repo vis below.
mygit repo new will create repository on remote server.
By default repository will be created with private visibility. This can be override with
MY_GIT[<remote name>.pri]="false" in configuration file
~/.mygit.conf on a per remote basis. Or override with
--pri/--pub in command line.
mygit repo vis will get visibility status from remote.
--pri/--pub to change visibility settings on remote server.
THERE IS NO CONFIRMATION FOR DELETION.
mygit repo del will delete repository from remote.
Github token need
delete_repo scope to delete repository through API. Either use a token with that scope in
MY_GIT[<remote name>.tok] or a separate token and put it in
mygit repo desc will get description of remote repository.
mygit repo desc "<description>" can update description of remote repository. Description needs to be in double quote.
mygit repo topic will get topics of remote repository.
mygit repo topic "topics ..." can update topics of remote repository. Multiple topics needs to be in double quote.
mygit repo ls will list up to 100 repositories on remote server. This command does not depend on repository.
By default archived repositories are filtered out. Use
--archive to show them also.
API Workflow Commands
mygit wf|workflow <command> are API base workflow commands.
All workflow commands must be ran at root of repository.
Workflow commands only work on GitHub repositories.
mygit wf will get all workflow information of a repository
mygit wf disp|dispatch <event> will trigger a
repository_dispatch event. Workflows file must configure accordingly.
New Repository Workflow
~/.mygit.conf is setup.
- Feature complete
- README.md completed
- add -g/-r checking
- add init repository name support
- add repo get info
- add repo ls –archive flag
- add usage
- change push master/all to flag(–)
- fix comment typo
- fix repo del github del token logic
- fix repo ls gogs/gitea support
- fix repo new visibility logic
- move desc, topic into repo
- Improve debug log
- change _mygit_group write to MY_GIT_GROUP directly
- change _mygit_remote write to MY_GIT_REMOTE directly
- change repo del allow independent of local remote
- change shebang to #!/usr/bin/env bash
- fix ARGP leak for push
- fix _in_group call missing "" for group
- fix _in_group call wrapped with $() incorrectly
- fix _in_group var conflict, change _g -> _x
- fix repo new visibility
- add workflow list and event dispatch for GitHub
The MIT License (MIT)
Copyright (c) 2020 John Siu
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.