git-elegant
An assistant who carefully automates routine work with Git.
usage: git elegant [-h | --help | help | --version | version]
or: git elegant <command> [-h | --help | help]
or: git elegant <command> [--no-workflows] [args]
or: git elegant [--no-workflows] <command> [args]
-h, --help, help displays help
--version, version displays program version
--no-workflows disables available workflows
There are commands used in various situations such as
enable Elegnat Git services
acquire-git Configures a Git installation.
acquire-repository Configures current repository.
clone-repository Clones a repository and configures it.
init-repository Initializes a new repository and configures it.
serve a repository
prune-repository Removes useless local branches.
enhance contribution rules
show-workflows Shows configured workflows in the repository.
make-workflow Makes a new workflow file for the repository.
polish-workflow Edits a given workflows file.
make day-to-day contributions
start-work Creates a new branch.
save-work Commits current modifications.
amend-work Amends some changes to the most recent commit.
show-work Shows a state of current work in progress.
polish-work Reapplies branch commits interactively.
interact with others
deliver-work Publishes current branch to a remote repository.
obtain-work Checkouts a remote branch matching by a name.
manage contributions
accept-work Incorporates a branch on top of the `master`.
release-work Releases available work as a new annotated tag.
show-release-notes Prints a release log between two references.
and others
show-commands Prints available Elegant Git commands.
Please visit https://elegant-git.bees-hive.org to find out more.
accept-work
usage: git elegant accept-work <branch>
Checkouts a given local or remote branch into a temporary one. Then, it makes
a rebase of the latest version of the default upstream branch (master
) with
current changes. The final rebased index merges using fast-forward strategy
into the default local branch and pushes into the default upstream branch
(origin/master
). After a successful push, the temporary branch is removed
as well as the given branch if it locates in origin
remote.
If there is a rebase in progress and it is initiated by this command, it will be continued instead; otherwise, the command stops.
The command uses branch and stash pipes to preserve the current Git state prior to execution and restore after.
Approximate commands flow is
==>> git elegant accept-work task-123
git fetch --all
git checkout --force -B __eg origin/task-123
git rebase origin/master
git checkout master
git merge --ff-only __eg
git push origin master:master
git branch --delete --force __eg
git push origin --delete task-123
acquire-git
usage: git elegant acquire-repository
Applies the "basics", "standards", and "aliases" configurations to the current
Git installation using git config --global
.
During the first execution, you will be asked to provide some information. After, Elegant Git will automatically detect what should be changed.
To find out what will be configured, please visit https://elegant-git.bees-hive.org/en/latest/configuration/
acquire-repository
usage: git elegant acquire-repository
Applies the "basics", "standards", "aliases", and "signature" configurations
to the current Git repository using git config --local
.
To find out what will be configured, please visit https://elegant-git.bees-hive.org/en/latest/configuration/
amend-work
usage: git elegant amend-work
Updates the most recent commit by adding some changes. The command will fail if you'll try to modify history of the default local branch.
Approximate commands flow is
==>> git elegant amend-work
git add --interactive
git diff --cached --check
git commit --amend
clone-repository
usage: git elegant clone-repository <repository>
Clones a repository into a new directory and runs its configuration.
Approximate commands flow is
==>> git elegant clone-repository git@github.com:bees-hive/elegant-git.git
git clone git@github.com:bees-hive/elegant-git.git
cd elegant-git
git elegant acquire-repository
deliver-work
usage: git elegant deliver-work [branch-name]
Updates the current branch by rebasing the default upstream branch. If there is a rebase in progress, the command will continue it instead of initiation a new one. Then, it pushes HEAD to the appropriate upstream branch.
By default, the name of remote branch is equal to the local one. If a local branch has an upstream branch configured, it will be used as a remote branch. If you provide a custom name of the remote branch, it will be used as a remote branch.
The command uses stash pipe to preserve the current Git state prior to execution and restore after.
If the push output contains an URL (like a link to create a pull request), it
will be open (in case if open
command is available) in a default browser.
Approximate commands flow is
==>> git elegant deliver-work
git fetch
git rebase origin/master
git push --set-upstream --force origin task-123:task-123
init-repository
usage: git elegant init-repository
Creates an empty Git repository (or reinitialize an existing one), runs its configuration, and creates an initial empty commit.
Approximate commands flow is
==>> git elegant init-repository
git init
git elegant acquire-repository
git commit --allow-empty --file a-message-of-initial-commit
git show
make-workflow
usage: git elegant make-workflow <command> <type> <location>
Makes a new workflow file for a given Elegant Git command and opens it for the
further scripting in the default text editor. The created file will have a
shebang line pointing to #!/usr/bin/env sh -e
and executable permissions.
That's why the created file becomes an executable one by default. All needed
directories will be created if any.
A type
defines whether it should be executed ahead
or after
the
given command.
And location
defines the availability such as personal (located at
.git/.workflows
) or common (located at .workflows
).
Approximate commands flow is
==>> git elegant make-workflow show-work ahead common
mkdir -p .workflows
touch .workflows/show-work-ahead
chmod +x .workflows/show-work-ahead
vim .workflows/show-work-ahead
obtain-work
usage: git elegant obtain-work <remote branch> [local branch]
Seeks across all upstreams for a branch matching by a given full or partial name. If there are more then 1 matching branch, execution stops with a corresponding error message. By default, the name of the local branch responds to the remote one. However, it can be overridden by giving a second argument.
Approximate commands flow is
==>> git elegant obtain-work new-feature task-133
git fetch --all
git checkout -B task-133 custom-remote/new-feature
polish-work
usage: git elegant polish-work
Reapplies branch commits using interactive rebase. It uses only new commits that
aren't in master
branch. If there is a rebase in progress, the command will
continue it.
Prior to the execution and in the case of rebase initiation, all uncommitted
tracked modifications will be temporally stashed. And they will be uncovered if
the rebase completes without errors, otherwise, you need to apply them manually
by running git stash pop
.
The command raises error 42 if it runs against master
branch.
The command uses stash pipe to preserve the current Git state prior to execution and restore after.
Approximate commands flow is
==>> git elegant polish-work
git rebase --interactive @~5
polish-workflow
usage: git elegant polish-workflow <file>
Opens a given workflow file in the default text editor. If given file is not present, the command raises an error.
Approximate commands flow is
==>> git elegant polish-workflow .workflows/show-work-ahead
vim .workflows/show-work-ahead
prune-repository
usage: git elegant prune-repository
Identifies useless branches within the current repository and removes them. A
branch is useless if it either has configured an unavailable upstream branch (1)
or does not have new commits comparing to master
branch (2).
1 - Usually, a local branch has this state when an appropriate remote branch was merged to a remote target branch and was removed. Since these manipulations were made on server side, the local branch is still present, but useless.
2 - This kind of branches appears when a branch is created for some purposes but does not have any commits nowadays. So, it is useless.
Approximate commands flow is
==>> git elegant prune-repository
git checkout master
git fetch --all
git rebase
git branch --delete --force task-24
git branch --delete --force 2349
git branch --delete --force task-1
The command works even if the remotes are unavailable.
release-work
usage: git elegant release-work [tag name]
Annotates the latest commit of master
branch with a given tag and publishes
it. The tag's message will be prepopulated using commits subjects (from oldest
to newest) between the last available tag and HEAD. If there are no tags, then
all commits will be used. The release notes will be either copied to clipboard
(if pbcopy
or xclip
is available) or printed to standard output using
git elegant show-release-notes
.
The command uses branch and stash pipes to preserve the current Git state prior to execution and restore after.
Approximate commands flow is
==>> git elegant release-work 1.2.0
git checkout master
git pull --tags
git tag --annotate --file tag-message --edit 1.2.0
git push --tags
git elegant show-release-notes smart 1.1.12 1.2.0
save-work
usage: git elegant save-work
Saves available changes as a new commit. You can choose which modifications should be added. If there are trailing whitespaces, the commit won't be performed.
Approximate commands flow is
==>> git elegant save-work
git add --interactive
git diff --cached --check
git commit
show-commands
usage: git elegant show-commands
Displays all available Elegant Git commands. This is useful for completion functions as well as for other cases when you need iteration over the available commands.
Approximate command's output is
==>> git elegant show-commands
start-work
show-commands
....
show-release-notes
usage: git elegant show-release-notes [<layout> | <layout> <from-reference> | <layout> <from-reference> <to-reference>]
Generates a release notes using commits subjects between the given references.
The commits are ordered from oldest to newest. By default, the from-reference
is the last available tag, and the to-reference
is a HEAD revision. If
there are no tags, all commits will be displayed.
There are two options for a layout
:
simple
prints the messages as a plain text (default one)smart
prints the messages in a form of adopted for a git hosting. If the hosting is unknown, the default layout is used. Now only GitHub is supported (an HTML output).
Approximate command's output is
==>> git elegant show-release-notes
Release notes
- Add `show-release-notes` command
- Add `release-work` command
show-work
usage: git elegant show-work
Shows a state of current work by displaying branch information, new commits
comparing to master
branch, uncommitted modifications, and available
stashes.
Approximate commands flow is
==>> git elegant show-work
git log --oneline master..@
git status --short
git stash list
show-workflows
usage: git elegant show-workflows
Shows all personal and common workflows files that are available in the repository.
Personal workflows are located in .git/.workflows
directory and common ones
are in \'.workflows` relatively to the repository root directory.
Approximate command's output is
==>> git elegant show-workflows
.git/.workflows/accept-work-after
.workflows/amend-work-ahead
.workflows/amend-work-after
.workflows/release-work-after
.workflows/save-work-ahead
.workflows/save-work-after
....
start-work
usage: git elegant start-work <name> [from-ref]
Creates a new local branch based on the latest version of the default upstream branch. If there are some uncommitted changes, they will be moved to the new branch.
from-ref
argument overrides the default upstream branch with a given one.
The command uses stash pipe to preserve the current Git state prior to execution and restore after.
Approximate commands flow is
==>> git elegant start-work task-123
git stash save elegant-git
git checkout master
git pull
git checkout -b task-123
git stash apply stash^{/elegant-git}
git stash drop stash@{0}
The command works even if a remote is unavailable.