{"id":20261719,"url":"https://github.com/pcdevil/g","last_synced_at":"2025-04-11T01:45:32.672Z","repository":{"id":71398188,"uuid":"192339977","full_name":"pcdevil/g","owner":"pcdevil","description":"a wrapper around git with additional feature extension.","archived":false,"fork":false,"pushed_at":"2025-02-16T14:41:36.000Z","size":127,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-24T22:51:22.885Z","etag":null,"topics":["cli","git","git-wrapper"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pcdevil.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-17T12:10:25.000Z","updated_at":"2025-02-16T14:41:39.000Z","dependencies_parsed_at":"2024-11-14T11:29:44.060Z","dependency_job_id":"e85a5022-ee85-4302-b976-22ab3a49a4ee","html_url":"https://github.com/pcdevil/g","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcdevil%2Fg","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcdevil%2Fg/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcdevil%2Fg/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pcdevil%2Fg/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pcdevil","download_url":"https://codeload.github.com/pcdevil/g/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248327863,"owners_count":21085258,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","git","git-wrapper"],"created_at":"2024-11-14T11:26:43.178Z","updated_at":"2025-04-11T01:45:32.652Z","avatar_url":"https://github.com/pcdevil.png","language":"Shell","readme":"# g\nA wrapper around **git** with additional feature extension.\nSee detailed functionality in the **[Features]** section!\n\n### Table of Contents\n- **[Install]**\n  - **[Prerequirements]**\n  - **[Steps]**\n- **[Predefined git config]**\n  - **[Abbreviation aliases]**\n  - **[Basic aliases]**\n  - **[Commit aliases]**\n    - **[Conventional Commit aliases]**\n  - **[Advanced aliases]**\n- **[Features]**\n  - **[g]**\n  - **[backup-branch]**\n  - **[conventional-commit]**\n  - **[set-user]**\n  - **[super-init]**\n  - **[switch-main]**\n- **[License]**\n\n---\n\n## Install\n\n### Prerequirements\n- unix-like system\n- [git] (minimum: v1.7+, recommended: v2.35+)\n- [zsh]\n\n### Steps\n1. Clone the repositoy to a desired folder:\n    ```zsh\n    $ git clone git@github.com:pcdevil/g.git ~/.g\n    ```\n\n2. Bootstrap it in your `.zshrc`:\n    ```zsh\n    # Load the init script of g. This will do the followings:\n    # - installs the `g` command\n    # - adds the project's bin directory to the $PATH\n    source $HOME/.g/g.plugin.zsh\n    ```\n\n3. (Optional) Install `gitconfig`:\n    ```zsh\n    $ git config --global --add include.path ~/.g/gitconfig\n    ```\n\n    __See **[Predefined git config]** section for more information about it.__\n\n4. Reload the terminal.\n\n## Predefined git config\nThe project provides an optional `gitconfig` to extend the default **git**\nconfig. Currently it only contains aliases, which can be sorted into three\ncategories, listed below.\n\n### Abbreviation aliases\nAbbreviation aliases are very simple: their purpose to give quicker access to a\nspecific git command.\n\n| Alias command | **git** command                  |\n| ------------- | -------------------------------- |\n| `g ae`        | `git blame` _(as in \"annotate\")_ |\n| `g br`        | `git branch`                     |\n| `g cl`        | `git clone`                      |\n| `g cp`        | `git cherry-pick`                |\n| `g d`         | `git diff`                       |\n| `g me`        | `git merge`                      |\n| `g ph`        | `git push`                       |\n| `g pl`        | `git pull`                       |\n| `g q`         | `git stash`                      |\n| `g re`        | `git restore`                    |\n| `g sh`        | `git show`                       |\n| `g sw`        | `git switch`                     |\n\n_Note_: [git restore] and [git switch] only available since **git** v2.23, below\nthat the `re` and the `sw` alias produces error!\n\n_Note_: All features of `g` also have an abbreviation alias, which described in\nthe their respective descriptions.\n\n### Basic aliases\nBasic aliases give flavour for everyday situation usages, while they still keep\nthe durability of the base command and allow free parametrisation for them.\n\n| Alias command | Equivalent **git** command           | Description                                                                             |\n| ------------- | ------------------------------------ | --------------------------------------------------------------------------------------- |\n| `g a`         | `git add --patch`                    | Add file chunks interactively                                                           |\n| `g a-f`       | `git add --intent-to-add`            | Set file as intended to add                                                             |\n| `g cp-n`      | `git cherry-pick --no-commit`        | Apply an existing commit without creating a new one                                     |\n| `g d-s`       | `git diff --staged`                  | Show staged changes                                                                     |\n| `g f`         | `git fetch --prune --all`            | Download references from all remote and remove any local reference that no longer exist |\n| `g me-m`      | `git merge --no-ff`                  | Merge and always create merge commit                                                    |\n| `g me-s`      | `git merge --no-edit`                | Merge and use suggested message                                                         |\n| `g me-ms`     | `git merge --no-ff --no-edit`        | Merge and always create merge commit with suggested message                             |\n| `g re-s`      | `git restore --staged`               | Restore staged changes                                                                  |\n| `g q-ph`      | `git stash push --include-untracked` | Move staged, dirty and untracked (but not ignored) changes into stash                   |\n| `g q-pl`      | `git stash pop`                      | Move uppermost changes from stash into working directory                                |\n| `g q-s`       | `git stash push --staged`            | Move staged only changes into stash                                                     |\n\n_Note_: [git stash push --staged] only available since **git** v3.35, below that the `g q-s` alias produces error!\n\n### Commit aliases\n\n| Alias command | Equivalent **git** command            | Description                                                                                                           |\n| ------------- | ------------------------------------- | --------------------------------------------------------------------------------------------------------------------- |\n| `g ci`        | `git commit --message=\"$@\"`           | Commit and use all arguments as message                                                                               |\n| `g ci-a`      | `git commit --amend`                  | Amend last commit                                                                                                     |\n| `g ci-as`     | `git commit --amend --no-edit`        | Amend last commit and use the same message                                                                            |\n| `g ci-ra`     | `git commit --fixup=amend:$1 ${@:2}`  | Commit as _amend_ (fixup and reword) for later [rebased with autosquash], see [git commit fixup] for more information |\n| `g ci-rf`     | `git commit --fixup=$1 ${@:2}`        | Commit as _fixup_ for later rebased with autosquash                                                                   |\n| `g ci-rr`     | `git commit --fixup=reword:$1 ${@:2}` | Commit as _reword_ for later rebased with autosquash                                                                  |\n\n#### Conventional Commit aliases\n\nThe `g` wrapper provides a feature called [conventional-commit] which accepts a\nsecond argument for _type_. The described aliases below bound this argument.\n\n| Alias command    | Equivalent **conventional-commit** command |\n| ---------------- | ------------------------------------------ |\n| `g cci-build`    | `git conventional-commit build`            |\n| `g cci-chore`    | `git conventional-commit chore`            |\n| `g cci-ci`       | `git conventional-commit ci`               |\n| `g cci-docs`     | `git conventional-commit docs`             |\n| `g cci-feat`     | `git conventional-commit feat`             |\n| `g cci-fix`      | `git conventional-commit fix`              |\n| `g cci-perf`     | `git conventional-commit perf`             |\n| `g cci-refactor` | `git conventional-commit refactor`         |\n| `g cci-style`    | `git conventional-commit style`            |\n| `g cci-test`     | `git conventional-commit test`             |\n\n### Advanced aliases\nContrary to the previous alias types, advanced aliases are designed to give\nsolution in a strict situation without taking account other type of application.\nSee the \"Notes\" section how they allow parametrisation for the underlying\n**git** command!\n\n| Alias command | Description                                        | Notes                                                                                                |\n| ------------- | -------------------------------------------------- | ---------------------------------------------------------------------------------------------------- |\n| `g l`         | Print a coloured, compact one-liner log            | Only `--pretty=format` used, any other [git log] argument works                                      |\n| `g ph-o`      | Set upstream to origin and push the current branch | Doesn't take any argument                                                                            |\n| `g re-2`      | Restore both staged and unstaged changes           | Any argument is passed through to [git restore]                                                      |\n| `g q-sh`      | Shows the content of a stash entry                 | An optional argument can be given and passed as index to the [git stash] _(see description section)_ |\n\n## Features\n\n### g\nThe `g` command is the starting point of all other script and provides a\nconvenient alias for `git`.\nCalling it without arguments executes the [git status] itself if the _CWD_ is a\ngit repository, otherwise calls the [git help] command.\n\n---\n\n### backup-branch\nCreates a new branch with the history of the current one for safekeeping.\n\nBy default the new branch's name follows the\n`backup/$currentBranch/%Y-%m-%d_%H-%M` pattern where `$currentBranch` is the\nname of the current branch and `%Y-%m-%d_%H-%M` is the current time in\n_year-month-day_hours-minutes_ format. This can be overriden by the optional\n`backup_name` argument.\n\n#### Signature\n```zsh\n$ g backup-branch [backup_name]\n```\n\n#### Arguments\n- `backup_name`: The name of the backup.\n\n### conventional-commit\nCreates a commit in compliance with the [Conventional Commit Message Format].\n\n#### Alias\n`cci`\n\n#### Signature\n```zsh\n$ g conventional-commit \u003ctype\u003e \u003cscope\u003e \u003cmessage\u003e\n```\n\n#### Arguments\n- `type`: The type part of the commit message, which is [described in the\n  guideline here].\n- `scope`: The scope part of the commit message.\n- `message`: The subject and body part of the commit message.\n\n#### Advanced use\nIn order to use this feature more conveniently, it's advised to create aliases\nfor commonly used types in the [git config], for example:\n```zsh\n$ git config --global alias.cci-feat 'conventional-commit feat'\n$ git config --global alias.cci-fix 'conventional-commit fix'\n$ git config --global alias.cci-test 'conventional-commit test'\n```\n\nThis will add new sections to the `~/.gitconfig` file with the following\ncontent:\n```gitconfig\n[alias]\ncci-feat = conventional-commit feat\ncci-fix = conventional-commit fix\ncci-test = conventional-commit test\n```\n\n_Note_: If you prefer, you can edit the config manually to achieve the same\nresult.\n\n_Note 2_: Command aliases are available in the predefined git config as\n[Conventional Commit aliases] too.\n\n---\n\n### set-user\nSets the username locally in the repository by reading it from the corresponding\nconfigs.\nIt comes handy when you are working on multiple git servers but it requires\nsetup to work.\n\nBy default it uses the current repository's _origin_ remote url and reads the\n`user.name`, `user.email` and `user.signingkey` configs from [git config] with\nthe benefit of the [url match functionality].\n\nWhen reading the configurations, `set-user` strips down the url and only works\nwith the _PROTOCOL + DOMAIN + TLD_ triple. If there is no match for the given\nurl it will fall back to the default values.\n\nThe `set-user` can turn on GPG signing for the repository too if the\n`user.signingkey` config is set. Once is enabled, `set-user` will sets\n`gpg.program` and `commit.gpgsign` configs too for the repository.\n\n#### Alias\n`su`\n\n#### Signature\n```zsh\n$ g set-user [repository_url]\n```\n\n#### Arguments\n- `repository_url`: Allows to redefine the repository url for the config reads.\n\n#### Setup\nFor proper working you have to add more options to the [git global config].\nThere is a way to do it by git commands (but it's not pretty):\n```zsh\n$ git config --global 'user.https://github.com.email' 'jakab@gipsz.eu'\n$\n$ git config --global 'user.https://example.org.email' 'jakab.gipsz@example.org'\n$ git config --global 'user.https://example.org.name' 'jakab.gipsz'\n$ git config --global 'user.https://example.org.signingkey' '0000000000000042'\n```\n\nThis will add new sections to the `~/.gitconfig` file with the following\ncontent:\n```gitconfig\n[user \"https://github.com\"]\nemail = jakab@gipsz.eu\n\n[user \"https://example.org\"]\nemail      = jakab.gipsz@example.org\nname       = jakab.gipsz\nsigningkey = 0000000000000042\n```\n\n_Note_: If you prefer, you can edit the config manually to achieve the same\nresult.\n\n#### Examples\n- Call it without argument inside a git repository.\n```zsh\n$ cd g\n$ # verify the e-mail has a default value\n$ git config --get --local user.email\njakab@gipsz.family\n$ git config --get remote.origin.url\ngit@github.com:pcdevil/g.git\n$ g set-user\n$ # get the new value for e-mail\n$ git config --get --local user.email\njakab@gipsz.eu\n$ # signingkey is not defined because it's not populated for the this repository\n$ git config --get --local user.signingkey\n$\n```\n\n- Passed url is respected too.\n```zsh\n$ mkdir ~/example-org-site\n$ cd ~/example-org-site\n$ g init\nInitialized empty Git repository in /Users/jakab.gipsz/example-org-site/.git\n$\n$ # this is equivalent as `g su \"https://example.org\"`\n$ g su \"git@dev.example.org:site-team/example-org-site.git\"\n$ # get the new values\n$ git config --get --local user.name\njakab.gipsz\n$ git config --get --local user.email\njakab.gipsz@example.org\n$ # for this use-case signingkey is populated too\n$ git config --get --local user.signingkey\n0000000000000042\n$\n```\n\n---\n\n### super-init\nInitiates a git repository in the current directory and populated `README.md`,\n`LICENSE.md` and `.gitignore` files.\n\nBy default the readme file will hold the name of the project and a link to the\nlicense file. Defining a description as argument will result to fill it the\nreadme file with it.\n\nThe license will be [MIT].\n\nTo make the `.gitignore` file the command will download the content from\nToptal's [gitignore.io].\n\nThe following templates are applied by default:\n- **Operating systems**: Linux, macOS, Windows\n- **Editors**: JetBrains, Sublime Text, Vim, Visual Studio Code\n- **Custom elements**: `[git root]/.tmp` directory, `.env` files, but negated\n  any `.gitkeep` file occurrences\n\nIf a _[type]_ is also defined then the appropriate programming language will be\nadded to the ignore too. Currently supported languages are `java`, `node`,\n`php`, `python` and `rust`.\n\nThe [switch-main] command will be also called with the create flag, ensuring the\ncorrect branch name by default from the first commit.\n\n#### Alias\n`si`\n\n#### Signature\n```zsh\n$ g super-init [type] [description]\n```\n\n#### Arguments\n- `type`: The _\"programming language\"_ to use for the `.gitignore` file.\n- `description`: Optional description for the `README.md`.\n\n---\n\n### switch-main\nThe `switch-main` command provides a clean way to change the current branch to\nthe default `main`. The command is created in the notion to avoid the usage of\nthe `master` naming for branch, which is [considered as oppressive phrasing] and\nsuggested to use alternatives.\n\n#### Alias\n`sw-m`\n\n#### Signature\n```zsh\n$ g switch-main [-c|--create]\n```\n\n#### Arguments\n- `-c|--create`: Creates the default branch. Useful during repository migration.\n\n#### Advanced use\nThe default branch name is `main`, but for legacy reasons there is also an\noption to modify what is considered to be the _main branch_: because **git**\nalso supports default branches (since 2.28.0) with [`init.defaultBranch` git\nconfig], this command also relies on that:\n\n```zsh\n$ # in a GitHub Pages project\n$ git rev-parse --abbrev-ref HEAD\nfeat/add-contact-info\n$ git config --local init.defaultBranch gh-pages\n$ g switch-main\n$ git rev-parse --abbrev-ref HEAD\ngh-pages\n```\n\n_Note_: This can be overwritten globally via the `git config --global` command.\n\n## License\nAvailable under the [MIT license].\n\n[Abbreviation aliases]: #abbreviation-aliases\n[Advanced aliases]: #advanced-aliases\n[backup-branch]: #backup-branch\n[Commit aliases]: #commit-aliases\n[conventional-commit]: #conventional-commit\n[Conventional Commit aliases]: #conventional-commit-aliases\n[Conventional Commit Message Format]: https://www.conventionalcommits.org/en/v1.0.0/#summary\n[Basic aliases]: #basic-aliases\n[considered as oppressive phrasing]: https://tools.ietf.org/id/draft-knodel-terminology-00.html#rfc.section.1.1\n[Features]: #features\n[g]: #g-1\n[git]: https://git-scm.com\n[git clone]: https://git-scm.com/docs/git-clone\n[git commit]: https://git-scm.com/docs/git-commit\n[git commit fixup]: https://git-scm.com/docs/git-commit#Documentation/git-commit.txt---fixupamendrewordltcommitgt\n[git config]: https://git-scm.com/docs/git-config\n[git global config]: https://git-scm.com/docs/git-config#Documentation/git-config.txt---global\n[git help]: https://git-scm.com/docs/git-help\n[git log]: https://git-scm.com/docs/git-log\n[git restore]: https://git-scm.com/docs/git-restore\n[git stash]: https://git-scm.com/docs/git-stash\n[git stash push --staged]: https://git-scm.com/docs/git-stash#Documentation/git-stash.txt---staged\n[git status]: https://git-scm.com/docs/git-status\n[git switch]: https://git-scm.com/docs/git-switch\n[rebased with autosquash]: https://git-scm.com/docs/git-rebase#Documentation/git-rebase.txt---autosquash\n[git-set-user]: #set-user\n[GitHub Pages]: https://help.github.com/en/github/working-with-github-pages/creating-a-github-pages-site#creating-a-repository-for-your-site\n[gitignore.io]: https://www.toptal.com/developers/gitignore\n[`init.defaultBranch` git config]: https://git-scm.com/docs/git-config#Documentation/git-config.txt-initdefaultBranch\n[Install]: #install\n[License]: #license\n[MIT]: https://opensource.org/licenses/MIT\n[MIT license]: LICENSE.md\n[Predefined git config]: #predefined-git-config\n[Prerequirements]: #prerequirements\n[set-user]: #set-user\n[Steps]: #steps\n[super-init]: #super-init\n[switch-main]: #switch-main\n[url match functionality]: https://git-scm.com/docs/git-config#Documentation/git-config.txt---get-urlmatchnameURL\n[zsh]: http://www.zsh.org/\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpcdevil%2Fg","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpcdevil%2Fg","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpcdevil%2Fg/lists"}