From 0c8adfa4ef82c3a7bf3a16daf4fb0b46966eb4aa Mon Sep 17 00:00:00 2001 From: Wesley Scholl <128409641+wesleyscholl@users.noreply.github.com> Date: Thu, 12 Sep 2024 13:38:39 -0400 Subject: [PATCH 01/13] - --- git-commit-push-script.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 git-commit-push-script.sh diff --git a/git-commit-push-script.sh b/git-commit-push-script.sh new file mode 100755 index 0000000..a183abd --- /dev/null +++ b/git-commit-push-script.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +# Create the alias +alias cm=' + +# Add all changes +git add -A + +# Extract ticket number from current directory +ticket=$(pwd | grep -oE "CRS-[0-9]+" | head -n 1) + +# Prompt for commit message +read -p "Enter commit message: " message + +# Prepare and execute commit command +git commit -S -m "$ticket - $message" + +# Push changes +git push +' From 0b0950e62ce7d89b132b5635b5ddcd97b4ec49e8 Mon Sep 17 00:00:00 2001 From: Wesley Scholl <128409641+wesleyscholl@users.noreply.github.com> Date: Thu, 12 Sep 2024 13:43:32 -0400 Subject: [PATCH 02/13] - --- git-commit-push-script.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/git-commit-push-script.sh b/git-commit-push-script.sh index a183abd..4650eb3 100755 --- a/git-commit-push-script.sh +++ b/git-commit-push-script.sh @@ -10,7 +10,8 @@ git add -A ticket=$(pwd | grep -oE "CRS-[0-9]+" | head -n 1) # Prompt for commit message -read -p "Enter commit message: " message +echo -n "Enter commit message: " +read message # Prepare and execute commit command git commit -S -m "$ticket - $message" From 5f86f99f9495f64f261ced4197bacdd97e00c0f1 Mon Sep 17 00:00:00 2001 From: Wesley Scholl <128409641+wesleyscholl@users.noreply.github.com> Date: Thu, 12 Sep 2024 13:45:34 -0400 Subject: [PATCH 03/13] - --- git-commit-push-script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-commit-push-script.sh b/git-commit-push-script.sh index 4650eb3..50e25ef 100755 --- a/git-commit-push-script.sh +++ b/git-commit-push-script.sh @@ -10,7 +10,7 @@ git add -A ticket=$(pwd | grep -oE "CRS-[0-9]+" | head -n 1) # Prompt for commit message -echo -n "Enter commit message: " +echo "Enter commit message: " read message # Prepare and execute commit command From 14c357b65b20deb406e61aceebc3d5927655e8b0 Mon Sep 17 00:00:00 2001 From: Wesley Scholl <128409641+wesleyscholl@users.noreply.github.com> Date: Thu, 12 Sep 2024 13:47:57 -0400 Subject: [PATCH 04/13] - --- git-commit-push-script.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/git-commit-push-script.sh b/git-commit-push-script.sh index 50e25ef..e4f84d2 100755 --- a/git-commit-push-script.sh +++ b/git-commit-push-script.sh @@ -10,8 +10,10 @@ git add -A ticket=$(pwd | grep -oE "CRS-[0-9]+" | head -n 1) # Prompt for commit message + echo "Enter commit message: " read message +echo "Commit message: $ticket - $message" # Prepare and execute commit command git commit -S -m "$ticket - $message" From 27ae83b5beaa0f964e80d21d7da9ad3ae0c5e85f Mon Sep 17 00:00:00 2001 From: Wesley Scholl <128409641+wesleyscholl@users.noreply.github.com> Date: Thu, 12 Sep 2024 13:53:43 -0400 Subject: [PATCH 05/13] - --- git-commit-push-script.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/git-commit-push-script.sh b/git-commit-push-script.sh index e4f84d2..d21c462 100755 --- a/git-commit-push-script.sh +++ b/git-commit-push-script.sh @@ -1,8 +1,5 @@ #!/bin/bash -# Create the alias -alias cm=' - # Add all changes git add -A @@ -20,4 +17,4 @@ git commit -S -m "$ticket - $message" # Push changes git push -' + From 3e6faf41d0b9b1eb0365cdb9bec2e5a070665ad5 Mon Sep 17 00:00:00 2001 From: Wesley Scholl <128409641+wesleyscholl@users.noreply.github.com> Date: Thu, 12 Sep 2024 13:54:28 -0400 Subject: [PATCH 06/13] - --- git-commit-push-script.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/git-commit-push-script.sh b/git-commit-push-script.sh index d21c462..e029c5c 100755 --- a/git-commit-push-script.sh +++ b/git-commit-push-script.sh @@ -1,4 +1,5 @@ #!/bin/bash +source ~/.bash_profile # Add all changes git add -A From 39f7bec393e4a89966b40e30817deb139a547acd Mon Sep 17 00:00:00 2001 From: Wesley Scholl <128409641+wesleyscholl@users.noreply.github.com> Date: Thu, 12 Sep 2024 13:56:04 -0400 Subject: [PATCH 07/13] - --- git-commit-push-script.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/git-commit-push-script.sh b/git-commit-push-script.sh index e029c5c..03c46fa 100755 --- a/git-commit-push-script.sh +++ b/git-commit-push-script.sh @@ -8,9 +8,7 @@ git add -A ticket=$(pwd | grep -oE "CRS-[0-9]+" | head -n 1) # Prompt for commit message - -echo "Enter commit message: " -read message +read -p "Enter commit message: " message echo "Commit message: $ticket - $message" # Prepare and execute commit command From 349e4e8d797ed672af8c742fc039929a86125d2f Mon Sep 17 00:00:00 2001 From: Wesley Scholl <128409641+wesleyscholl@users.noreply.github.com> Date: Thu, 12 Sep 2024 13:57:40 -0400 Subject: [PATCH 08/13] - Commit description - code changes, tests, etc. --- git-commit-push-script.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/git-commit-push-script.sh b/git-commit-push-script.sh index 03c46fa..2fbe807 100755 --- a/git-commit-push-script.sh +++ b/git-commit-push-script.sh @@ -16,4 +16,3 @@ git commit -S -m "$ticket - $message" # Push changes git push - From 40c4752774afe0cd063504d05fb8af4b0a150ee4 Mon Sep 17 00:00:00 2001 From: Wesley Scholl <128409641+wesleyscholl@users.noreply.github.com> Date: Thu, 12 Sep 2024 13:58:51 -0400 Subject: [PATCH 09/13] - Added new ticket regex --- git-commit-push-script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/git-commit-push-script.sh b/git-commit-push-script.sh index 2fbe807..4dab746 100755 --- a/git-commit-push-script.sh +++ b/git-commit-push-script.sh @@ -5,7 +5,7 @@ source ~/.bash_profile git add -A # Extract ticket number from current directory -ticket=$(pwd | grep -oE "CRS-[0-9]+" | head -n 1) +ticket=$(echo $base_branch | grep -o -E '([A-Za-z]+-[0-9]{3,}|[A-Za-z]+-[0-9]{3,})') # Prompt for commit message read -p "Enter commit message: " message From 130c6f6d28e702479e454ad3f436d6480aa25002 Mon Sep 17 00:00:00 2001 From: Wesley Scholl <128409641+wesleyscholl@users.noreply.github.com> Date: Thu, 12 Sep 2024 14:00:24 -0400 Subject: [PATCH 10/13] CRS-12345 - Added base branch --- git-commit-push-script.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/git-commit-push-script.sh b/git-commit-push-script.sh index 4dab746..46c4abc 100755 --- a/git-commit-push-script.sh +++ b/git-commit-push-script.sh @@ -4,6 +4,9 @@ source ~/.bash_profile # Add all changes git add -A +# Get branch name +base_branch=$(git rev-parse --abbrev-ref HEAD) + # Extract ticket number from current directory ticket=$(echo $base_branch | grep -o -E '([A-Za-z]+-[0-9]{3,}|[A-Za-z]+-[0-9]{3,})') From c76b73c94ffaa855c0e060ba8e9cae9e6619511d Mon Sep 17 00:00:00 2001 From: Wesley Scholl <128409641+wesleyscholl@users.noreply.github.com> Date: Thu, 12 Sep 2024 14:02:12 -0400 Subject: [PATCH 11/13] CRS-12345 - test --- git-commit-push-script.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/git-commit-push-script.sh b/git-commit-push-script.sh index 46c4abc..e63423b 100755 --- a/git-commit-push-script.sh +++ b/git-commit-push-script.sh @@ -19,3 +19,4 @@ git commit -S -m "$ticket - $message" # Push changes git push + From be6fe58303659f8703c8f88e27595b1ee2cadb59 Mon Sep 17 00:00:00 2001 From: Wesley Scholl <128409641+wesleyscholl@users.noreply.github.com> Date: Thu, 12 Sep 2024 14:29:17 -0400 Subject: [PATCH 12/13] CRS-12345 - Test message --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bed80aa..4cdacc1 100644 --- a/README.md +++ b/README.md @@ -1 +1,2 @@ -# git-commit-push-script \ No newline at end of file +# git-commit-push-script - Automating commit and push to GitHub + From e78638325374cc5fa1ed91537cd23091f955c3d6 Mon Sep 17 00:00:00 2001 From: Wesley Scholl <128409641+wesleyscholl@users.noreply.github.com> Date: Thu, 12 Sep 2024 15:14:51 -0400 Subject: [PATCH 13/13] CRS-12345 - Added more sections to readme --- README.md | 101 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 100 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4cdacc1..ed72765 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,101 @@ -# git-commit-push-script - Automating commit and push to GitHub +# git-commit-push-script - Automating Staging, Committing and Pushing to GitHub 👨🏻‍💻➡️ + +Manually typing staging, commit messages, and push commands is repetative. Especially copying the ticket number into the commit message. Save time using this shell script. + +## Table of Contents +* [What this script automates](#what-this-script-automates) +* [User input required](#user-input-required) +* [Requirements](#requirements) +* [Installation](#installation) +* [Usage](#usage) +* [License](#license) + +## What this script automates: + +| Name | Description | +| --- | --- | +| Git Staging | Staging any modified files for commit using `git add -A`. | +| Git Commit Message | Copying the ticket number of the Jira ticket as the commit message prefix. Example: `[CRS-12345]`. | +| Git Commit | Committing staged files with the commit message using `git commit -S -m ""`. | +| Git Push | Pushing local commits to remote branch with `git push`. | + +## User input required: + +| Name | Description | +| --- | --- | +| Alias Command | The alias command to be used for the script: `cm`. | +| Commit Message | The commit message with description of the changes made. | + +## Requirements + +| Name | Description | Link, Location, or Command | +| --- | --- | --- | +| Terminal or Shell | A terminal or shell for configuring and running the script. | [Download Terminal](https://www.apple.com/macos/terminal/) | +| `Git Bash` ***Required for Windows** | Git Bash provides a UNIX command line emulator for windows which can be used to run Git, shell commands, and much more. | [Download Git Bash](https://gitforwindows.org/) | + + +## Installation + +1. Clone the git-commit-push-script repository to your local computer. + +```shell +git clone https://github.com/wesleyscholl/git-commit-push-script.git +``` + +2. Navigate to the git-commit-push-script directory with your terminal, shell, command line, or bash. + +```shell +cd git-commit-push-script +``` + +3. Make the script executable by running the following command: +```shell +chmod +x git-commit-push-script.sh +``` + +4. Configure the alias command for the script in zshrc or bash_profile. +```shell +alias cm='bash /path/to/git-commit-push-script/git-commit-push-script.sh' +``` + +5. Reload the terminal or shell configuration by running the following command: +```shell +source ~/.zshrc +# OR # +source ~/.bash_profile +``` + +## Usage + +6. Test the script by running the following command from a Git repository directory with a Jira ticket branch. + +```shell +cm +``` + +7. Enter your commit message when prompted. +```shell +Enter commit message: +``` + +8. The script will stage, commit with the ticket prefix, and push the changes to the remote branch. +```shell +Enter commit message: Test message +Commit message: CRS-12345 - Test message +[CRS-12345-Git-Script-Test be6fe58] CRS-12345 - Test message + 1 file changed, 2 insertions(+), 1 deletion(-) +Enumerating objects: 5, done. +Counting objects: 100% (5/5), done. +Delta compression using up to 16 threads +Compressing objects: 100% (3/3), done. +Writing objects: 100% (3/3), 643 bytes | 643.00 KiB/s, done. +Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 +To https://github.com/wesleyscholl/git-commit-push-script.git + c76b73c..be6fe58 CRS-12345-Git-Script-Test -> CRS-12345-Git-Script-Test +``` + +9. Enjoy the script! + +## License +This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.