Git Assistant Skill
This skill helps manage Git repositories by automating common workflows like committing, pushing, and setting up remote repositories on GitHub.
Core Workflow: Assisting with Commits and Pushes
This is the primary workflow for when a user wants to save and upload their work.
User's Goal: "I've finished my changes, help me commit and push them."
1. Check Git Status
Always start by checking the status of the repository to understand which files have been modified, staged, or are untracked.
Use the get-git-status.sh script for a concise, machine-readable output.
bash scripts/get-git-status.sh
The output is from git status --porcelain=v1. For example, M README.md means README.md is modified but not staged. A src/new.py means src/new.py is a new, staged file.
2. Stage Files
If there are modified files that are not staged, ask the user which files they want to include in the commit.
git add <file1> <file2> ...
3. Generate a Commit Message
A good commit message is crucial.
- Analyze the diff: Look at the staged changes using
git diff --staged. - Consult best practices: Use the
references/commit-best-practices.mdguide to structure the message. - Propose a message: Based on the changes and the guide, propose a commit message to the user. For example:
feat(api): add new /health endpoint. - Confirm with user: Always confirm the proposed message before committing.
4. Perform the Commit
Once the message is approved, run the commit command.
git commit -m "feat(api): add new /health endpoint"
5. Push to Remote
Attempt to push the changes to the remote repository.
git push
6. Handle "No Remote" Error (Crucial)
This is a common failure point. If git push fails with an error like fatal: No configured push destination, it means the local repository is not connected to a remote one.
This is the key guidance section of the skill:
- Inform the user: Explain that the push failed because no remote repository is configured.
- Offer a solution: Ask if they would like you to create a new repository on their GitHub account and link it.
- Check for
ghCLI: Before proceeding, check if theghcommand is available (command -v gh).- If
ghis NOT installed: Inform the user that the GitHub CLI (gh) is needed. Explain its purpose (to create repos from the command line) and ask if they want you to guide them through the installation. If they agree, read the instructions fromreferences/github-cli-setup.mdand present them to the user. Do not proceed untilghis installed and authenticated. - If
ghis installed: Proceed to the next step.
- If
- Get Repository Name: Ask the user for a name for the new GitHub repository. A good default is the name of the current directory.
- Run the script: Execute the
create-github-repo.shscript with the chosen repository name.bash scripts/create-github-repo.sh <repo-name> - Confirm Success: The script will create the repo, add it as the
originremote, and perform the initial push. The script's output will confirm success. Relay this to the user.
Other Guidance
- For general questions about Git best practices (branching, merging, etc.), you can also consult
references/commit-best-practices.mdto inform your answers.