Tuesday, September 3, 2024

git commands

Following are basic git commands which should be sufficient for most of the git use :

git fetch
git pull
git commit
git push

Automated script to commit:

#!/bin/bash
ssh qspcadmin@USAZLINUXQSPCQ01 << EOF

cd /stage/qspcadmin/projects/sas
git fetch
git pull
git add .
git commit -m "Automated Commit"
git push

EOF

Automated bashrc function to commit with good message:

function gpt_commit() {
    diff=$(git diff)
    response=$(curl -s -X POST https://api.openai.com/v1/chat/completions \
      -H "Authorization: Bearer $OPENAI_API_KEY" \
      -H "Content-Type: application/json" \
      -d @- <<EOF
{
      "model": "gpt-4o-mini",
      "messages": [
        {
          "role": "system",
          "content": "You are an assistant that writes concise and informative git commit messages based on the provided git diff."
        },
        {
          "role": "user",
          "content": "$diff"
        }
      ],
      "temperature": 0.3
}
EOF
    )
    commit_message=$(echo "$response" | grep '"content":' | cut -d '"' -f 4)
    echo "Generated commit message: $commit_message"
    git commit -m "$commit_message"
}
 

No comments:

Post a Comment