GitLib is a library of utility functions for daily/commonly used Git commands. It provides methods to ease usage of some Git commands and to standardizing processes and commit messages.
GitLib is meant for anyone that uses Git from the terminal, making the daily work faster and preventing commons typos. Also it is a tool to encourage the usage of task-reference messages when commiting changes by standardizing them, allowing, that way, the integration of Git with issue tracking systems (i.e.: systems that scan issue IDs in messages).
NOTE: First of all, you need to have Git available on your computer, you can check if it is installed by typing git
in your terminal. If it is not, you can download and install from the Git download page.
-
Check out a clone of this repository to a location of your choice;
-
Include the installation file within your ~/.bash_profile or ~/.bashrc file:
source <path_to_gitlib>/setup.sh
-
You can also add configuration commands
Further configurations are not necessary.
<message>
: The commit message.
-p
: Push the commit.-s
: Commits only already stagged files.
Prepare the unstaged and new files for the next commit and then commit changes.
When you do a gcommit
, you'll be prompted to choose the prefix specifying the referred commit. The available options are: FIX
, FEAT
, TEST
, REFACTOR
, DOC
, REVERT
.
If the branch name contains a task number, it'll be used in the commit message, otherwise, a task number need to be prompted to confirm the action. The possible answers are:
y
ors
: Assumes0
as the task number;n
: Aborts the commit;<number>
: The task number (e.g.: 1234). Can be multivalued, comma separated values are valid (e.g.: 123, 456).
IMPORTANT: The commit message passed as argument is customized based on the current branch name. If the branch name match the pattern:
- b_task_1234: The message will be formatted using the task number 1234.
- b_PREFIX_1234: The message will be formatted using the task prefix PREFIX and task number 1234.
IF the commit prefix is REVERT
, instead of asking for the task number, you'll be prompted to speficy the ID of the target commit (SHA1 hash).
Current branch: master
>
gcommit -p "Added the save button click event"
> Answer 1: FEAT
> Answer 2: 123, 456
# Will result in the following commands:
>git add .
>git commit -m "[FEAT][#PREFIX-123, #PREFIX-456]: Added the save button click event"
>git push origin master
Current branch: master
>
gcommit -s "Added tests to the save button click event"
> Answer 1: TEST
> Answer 2: 123
# Will result in the following commands:
>git commit -m "[TEST][#PREFIX-123]: Added tests to the save button click event event"
Current branch: b_task_1234
>
gcommit "Added the save button click event"
> Answer 1: FIX
# Will not ask the task number
# Will result in the following commands:
>git add .
>git commit -m "[FIX][#PREFIX-1234]: Fixed the save button click event"
Current branch: b_CUSTOMPREFIX_1234
>
gcommit "Added the save button click event"
> Answer 1: FEAT
# Will not ask the task number
# Will result in the following commands:
>git add .
>git commit -m "[FEAT][#CUSTOMPREFIX-1234]: Added the save button click event"
<branch_name>
: [Optional] the branch which changes will be pulled, if none is specified, the current branch will be used.
Incorporates remote changes into the current branch.
Current branch: master
>
gpull
# Will result in the following commands:
>git pull origin master
>
gpull other_branch
# Will result in the following commands:
>git pull origin other_branch
<branch_name>
: [Optional] the branch which changes will be pushed, if none is specified, the current branch will be used.
Updates remote branch sending local commits.
Current branch: master
>
gpush
# Will result in the following commands:
>git gush origin master
>
gpush other_branch
# Will result in the following commands:
>git gush origin other_branch
-b
: Creates and checks out to a new branchActually, it will accept any ofgit branch
standard options.
<branch_name>
: The branch which will be switched to.
Prepare the local project for working on a specifc branch, switching the actual branch for the new one.
Current branch: master
>
gout -b b_task_1234
# Will result in the following commands:
>git checkout -b b_task_1234
- <branch_name>: The branch which commits will be merged
Incorporates changes from the named commits of the specified branch into the current branch.
IMPORTANT: Before merging, the gpull
command will be executed. It will not cause any harmful effect, if there is any remote commit not yet fetched into the local repository, the git merge
will fail and you will need to execute git pull
anyway.
Current branch: master
>
gmerge b_task_1234
# Will result in the following commands: >gpull
>git merge b_task_1234
Displays paths that have differences between the index file and the current HEAD commit. Simplifying: it is just a contraction of git stauts
command, the standard options and arguments will work.
Current branch: master
>
gstatus
# Will result in the following commands: >git status
Discards all stagged and unstagged changes and local (unpushed) commits. Only use this if you are really sure of what you are doing. There is no comming back.
>
greset
# Will result in the following commands:
>git checkout .
>git reset .
>git reset --soft HEAD
There are some options that can be configured. All the configurations can be changed using the gconfig
command while passing the configuration name as arguments. The following items are the currently available options:
<new_prefix>
: The prefix used before the task number
Changes the actual task-reference prefix that is used within the gcommit
command. It's used to compose the Jira task ID.
<new_log_level>
: The new log level of the tool
Changes the actual log level of GitLib commands. The currently available levels are:
- err: Error
- war: Warning
- info: Information
- debug: Debug
- Log level: info
<boolean>
: true or false.
When debug mode is true
, all commands will not cause changes to the git project. Useful with debug logging.
False.
Luiz Felipe Nazari