Skip to content

Commit b04d65e

Browse files
authoredSep 23, 2024··
Merged to main
2 parents 87080f5 + 5035058 commit b04d65e

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed
 

‎README.md

+28-25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# git-commit-push-script - Automating Staging, Committing and Pushing to GitHub 👨🏻‍💻➡️
1+
# git-commit-push-script - Automating Staging, Committing and Pushing to GitHub with Gemini AI 👨🏻‍💻➡️
22

3-
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.
3+
Staging, committing, and pushing code is a repetative manual process. Writing detailed commit messages and adding ticket numbers should be automated using AI. Save time using this shell script powered by Gemini AI.
44

55
## Table of Contents
66

@@ -13,26 +13,28 @@ Manually typing staging, commit messages, and push commands is repetative. Espec
1313

1414
## What this script automates
1515

16-
| Name | Description |
17-
| ------------------ | -------------------------------------------------------------------------------------------------- |
18-
| Git Staging | Staging any modified files for commit using `git add -A`. |
19-
| Git Commit Message | Copying the ticket number of the Jira ticket as the commit message prefix. Example: `[CRS-12345]`. |
20-
| Git Commit | Committing staged files with the commit message using `git commit -S -m "<commit message>"`. |
21-
| Git Push | Pushing local commits to remote branch with `git push`. |
16+
| Name | Description |
17+
| -------------------------------- | -------------------------------------------------------------------------------------------------- |
18+
| Git Staging | Staging any modified files for commit using `git add -A`. |
19+
| Git Commit Message Ticket Title | Copying the ticket number of the Jira ticket as the commit message prefix. Example: `[CRS-12345]`. |
20+
| Writing Commit Messages Using AI | The script uses Gemini AI to generate commit messages using `git diff --cached`. |
21+
| Git Commit | Committing staged files with the commit message using `git commit -S -m "<commit message>"`. |
22+
| Git Push | Pushing local commits to remote branch with `git push`. |
23+
| Git Push Retry (Pull & Push) | If a push fails, the script will `git pull` from the remote branch and push again. |
2224

2325
## User input required
2426

2527
| Name | Description |
2628
| -------------- | -------------------------------------------------------- |
2729
| Alias Command | The alias command to be used for the script: `cm`. |
28-
| Commit Message | The commit message with description of the changes made. |
2930

3031
## Requirements
3132

3233
| Name | Description | Link, Location, or Command |
3334
| ------------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------- |
3435
| Terminal or Shell | A terminal or shell for configuring and running the script. | [Download Terminal](https://www.apple.com/macos/terminal/) |
3536
| `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/) |
37+
| Google Gemini API Key | A Gemini API key is required to use Gemini AI to generate commit messages. | [Get Gemini API Key](https://www.getgemini.ai/) |
3638

3739
## Installation
3840

@@ -60,7 +62,14 @@ chmod +x git-commit-push-script.sh
6062
alias cm='bash /path/to/git-commit-push-script/git-commit-push-script.sh'
6163
```
6264

63-
5. Reload the terminal or shell configuration by running the following command:
65+
5. Add your Gemini API key to your bash or zsh configuration file (e.g., .zshrc or .bash_profile).
66+
67+
```shell
68+
export GEMINI_API_KEY=<your-gemini-api-key>
69+
```
70+
71+
72+
6. Reload the terminal or shell configuration by running the following command:
6473

6574
```shell
6675
source ~/.zshrc
@@ -70,33 +79,27 @@ source ~/.bash_profile
7079

7180
## Usage
7281

73-
6. Test the script by running the following command from a Git repository directory with a Jira ticket branch.
82+
7. Test the script by running the following command from a Git repository directory with a Jira ticket branch (Example - `TEST-1234-Your-GitHub-Branch`).
7483

7584
```shell
7685
cm
7786
```
7887

79-
7. Enter your commit message when prompted.
80-
81-
```shell
82-
Enter commit message: <Enter your commit message here>
83-
```
84-
85-
8. The script will stage, commit with the ticket prefix, and push the changes to the remote branch.
88+
9. The script will stage, request the commit message from Gemini with the `git diff`, commit with the ticket prefix and message, and push the changes to the remote branch.
8689

8790
```shell
88-
Enter commit message: Test message
89-
Commit message: CRS-12345 - Test message
90-
[CRS-12345-Git-Script-Test be6fe58] CRS-12345 - Test message
91-
1 file changed, 2 insertions(+), 1 deletion(-)
91+
[TEST-1234 f94df31] TEST-1234 Fix: Remove unnecessary text from Gemini prompt
92+
1 file changed, 1 insertion(+), 1 deletion(-)
93+
Branch 'TEST-1234' exists on remote. Pushing changes.
9294
Enumerating objects: 5, done.
9395
Counting objects: 100% (5/5), done.
9496
Delta compression using up to 16 threads
9597
Compressing objects: 100% (3/3), done.
96-
Writing objects: 100% (3/3), 643 bytes | 643.00 KiB/s, done.
97-
Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
98+
Writing objects: 100% (3/3), 633 bytes | 633.00 KiB/s, done.
99+
Total 3 (delta 2), reused 0 (delta 0), pack-reused 0 (from 0)
100+
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
98101
To https://github.com/wesleyscholl/git-commit-push-script.git
99-
c76b73c..be6fe58 CRS-12345-Git-Script-Test -> CRS-12345-Git-Script-Test
102+
ead30af..f94df31 TEST-1234 -> TEST-1234
100103
```
101104

102105
## Troubleshooting

‎git-commit-push-script.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ diff=$(git diff --cached)
1717
diff=$(echo $diff | sed 's/\\/\\\\/g' | sed 's/"/\\"/g' | sed 's/\n/\\n/g')
1818

1919
# Prepare the Gemini API request
20-
gemini_request='{"contents":[{"parts":[{"text": "Write a git commit message (commit message title 72 character maximum and commit message summary 50 character maxiumum) for the following git diff: '"$diff"' The format should be as follows (without titles): <commit message title> (2 new lines) <commit message summary>"}]}]}'
20+
gemini_request='{"contents":[{"parts":[{"text": "Write a git commit message (commit message title 72 character maximum and commit message summary 50 character maxiumum) for the following git diff: '"$diff"' The format should be as follows (without titles, back ticks, or markdown fomatting): <commit message title> (2 new lines) <commit message summary>"}]}]}'
2121

2222
# Get commit message from Gemini API
2323
commit_message=$(curl -s \

0 commit comments

Comments
 (0)
Please sign in to comment.