commit-hook
v1.9.7
Published
A simple npm package to manage Git hooks with `pre-commit` and `pre-push` hooks. This package helps automate tasks before committing or pushing changes, ensuring that your code adheres to your specified rules.
Readme
Commit Hook
A simple npm package to manage Git hooks with pre-commit and pre-push hooks. This package helps automate tasks before committing or pushing changes, ensuring that your code adheres to your specified rules.
Installation
npm i -g commit-hookRun this command to initialize git hooks
npx init-git-hookUsage
Once installed, you can configure the pre-commit and pre-push hooks in your package.json file. These hooks can run scripts or tools you specify before you commit or push your code.
Hooks Available
pre-commit
Runs before you make a commit. This can be used for tasks such as:
- Code linting
- Formatting
- Unit testing
pre-push
Runs before you push your changes to a remote repository. This can be used for tasks like:
- Running tests
- Verifying build integrity
Example Workflow
- Install the
git-hookpackage. - Add the scripts to the
package.jsonunder"scripts". - Once the hooks are configured, they will run automatically when you execute the corresponding Git commands:
git commitwill trigger thepre-commithook.git pushwill trigger thepre-pushhook.
Customizing Hooks
You can customize the behavior of the hooks by adjusting the scripts in your package.json. For example, you can use tools like eslint, prettier, or any other commands that fit your project's needs.
Git Aliases
Initialize Git Aliases
Run this command to initialize git aliases:
npx init-git-aliasResets Git Aliases
If you want to reset your Git aliases, you can run this command:
npx reset-git-aliasThis table summarizes the Git aliases you can set up for various Git commands.
| Alias | Command | Description |
| ------------------------ | ---------------------------------------------------------- | --------------------------------------------------------- |
| git st | status | Show the status of the repository |
| git co | checkout | Switch branches or restore working directory files |
| git br | branch | List, create, or delete branches |
| git cb <name> | !git checkout -b <name> | Create and switch to a new branch |
| git cm <message> | commit -m <message> | Commit changes with a message |
| git ac <message> | !git add . && git commit -m <message> | Add all changes and commit them with a message |
| git acp <msg> <branch> | !git add . && git commit -m "$1" && git push origin "$2" | Add, commit, and push in one step |
| git pl | pull | Fetch and integrate with another repository or branch |
| git plo | pull origin | Fetch from the remote repository origin |
| git ps | push | Update the remote repository with local commits |
| git pso | push origin | Push changes to the remote repository origin |
| git lg | log --oneline --graph --decorate --all | Show the commit history in a pretty graph format |
| git df | diff | Show differences between changes in the working directory |
| git rs | reset --soft HEAD~1 | Undo the last commit but keep changes staged |
| git rb | rebase | Reapply commits on top of another base commit |
| git rm | remote -v | Show remote URLs for the repository |
| git cl | !git clean -fd | Remove untracked files and directories |
| git stc | diff --cached | Show staged changes |
| git hf <file> | log --follow --oneline --graph | Show the commit history of a specific file |
| git dbr <branch> | branch -d <branch> | Delete a local branch |
| git drbr <branch> | !git push origin --delete <branch> | Delete a remote branch |
| git dl | diff HEAD | Show changes since the last commit |
| git sta | stash apply | Apply the last stash |
| git std | stash drop | Delete the last stash |
| git utf | ls-files --others --exclude-standard | Show untracked files |
| git rbi | rebase -i | Squash commits interactively |
| git prl | log --pretty=format:'%h %s (%an, %ar)' | Show commit information in a readable format |
How to Use the Aliases
After setting up the aliases, use them just like any regular Git command. For example:
To check the status of your repository, run:
git stTo commit changes with a message, use:
git cm "My commit message"To create and switch to a new branch:
git cb new-branch-nameTo pull from the remote repository
origin:git ploTo push to the remote repository
origin:git pso
Contributing
If you would like to contribute to the development of this package, please fork the repository and create a pull request with your changes. Ensure that your code adheres to the existing code style and includes tests if necessary.
License
MIT License
