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
Features
- Info
- debug
- remote
- group
- Selector
- -g/–group
- -r/–remote
- Git Base Commands
- fetch
- init
- push
- –master
- –all
- API Base Commands
- repo/repository
- –pri/–private
- –pub/–public
- del/delete
- ls/list
- –archive
- new
- vis/visibility
- desc/description
- topic/topics
- disp/dispatch
- list
- dispatch
- repo/repository
Limitation
- Strict option/argument order
- Minimum command line error detection
- Current supported git servers
- gitea
- github
- gogs
- API commands must be executed at root of repository
Usage
|
|
Configuration File
Following configuration will be used in all examples:
|
|
Testing
|
|
Example below can be tested inside mygit
dir.
Debug
Use following to enable debug output:
|
|
Info
The remote
and group
command provide a quick way to see what is configured.
remote
To show all remotes
configured:
|
|
Output:
|
|
group
To show all groups
configured:
|
|
Output:
|
|
Selector
mygit
allow command applied to groups or remotes through the use of -g/--group
and -r/--remote
. This applies to all commands except remote
and group
mentioned above.
-g/--group
and -r/--remote
must be placed right after mygit
and before any command.
-g/–group
|
|
-r/–remote
|
|
-g/--group
and -r/--remote
can be used at the same time.
|
|
Git Base Commands
init
, fetch
, push
are git base commands.
init
mygit init
will clear all existing remote and add remote base on -g
/-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.
Before mygit init
:
|
|
mygit init
without selector:
|
|
mygit init
with group internal:
|
|
mygit init
with repository name:
|
|
push
mygit push
will do git push
and git push --tag
base on -g
/-r
selector. If no group nor remote are specified, all configured remotes will be pushed in sequence.
|
|
|
|
mygit push
support options --master
and --all
–master
If --master
is used, mygit push
will push to upstream(-u
) master branch.
|
|
–all
If --all
is used, mygit push
will push all branches(--all
).
|
|
fetch
fetch
will do git fetch
base on -g
/-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.
Remote Information
mygit repo
without specifying additional command will retrieve repository information from remote server.
Visibility Flags
--pri
, --private
, --pub
, --public
are options for repo new
and repo vis
below.
new
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.
|
|
|
|
|
|
vis/visibility
mygit repo vis
will get visibility status from remote.
|
|
Use --pri/--pub
to change visibility settings on remote server.
|
|
del/delete
THERE IS NO CONFIRMATION FOR DELETION.
mygit repo del
will delete repository from remote.
|
|
Github
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 MY_GIT[<remote name>.del]
.
desc/description
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.
|
|
topic/topics
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.
|
|
ls/list
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.
List Workflow
mygit wf
will get all workflow information of a repository
|
|
Dispatch
mygit wf disp|dispatch <event>
will trigger a repository_dispatch
event. Workflows file must configure accordingly.
Workflow file:
|
|
|
|
New Repository Workflow
Assuming ~/.mygit.conf
is setup.
|
|
Repository
Contributors
Change Log
- 0.1.0
- Feature complete
- 0.2.0
- 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
- 0.2.1
- 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
- 0.2.2
- fix repo new visibility
- 0.2.3
- add workflow list and event dispatch for GitHub
License
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.