Push the current project to a GitHub remote repository with a single workflow.
Follow these steps in order:
Before doing anything else, determine the GitHub repository URL.
Read the repo mapping file at references/repo-map.json (relative to this skill's directory). This file maps local project paths to their GitHub URLs.
Compare the current working directory (the project the user wants to push) against the keys in the mapping.
If a mapping is found: Use the stored URL. Tell the user: "检测到该项目对应的仓库:,直接使用。"
If no mapping is found: Ask the user to provide the GitHub repository URL. Accept formats like:
https://github.com/user/repo.gitgit@github.com:user/repo.githttps://github.com/user/repoIf the user hasn't provided a URL yet, ask: "请提供GitHub仓库地址(例如 https://github.com/user/repo.git):"
Run git status to check if the current directory is a Git repository.
If NOT a Git repository:
git initgit add . to stage all filesgit commit -m "Initial commit"git remote add origin <URL> to add the remotegit branch -M <current-branch> to rename to the detected branch nameIf already a Git repository:
Check if a remote named origin already exists:
git remote get-url originorigin exists, run git remote add origin <URL>Check for uncommitted changes with git status --porcelain.
If there are uncommitted changes:
git diff --cached to see staged changesgit diff to see unstaged changesgit add .type(scope): brief summaryfeat (new feature), fix (bug fix), chore (maintenance), docs, refactor, style, testgit commit -m "<generated message>"If there are no uncommitted changes: Proceed directly to push.
Detect the current branch: git branch --show-current
Try normal push first: git push -u origin <branch>
If the push fails with a connection error (e.g., "Could not connect to server", "Failed to connect", timeout, network unreachable), check if the remote URL uses HTTPS protocol:
Run git remote get-url origin to inspect the current URL.
If the URL starts with https://, retry up to 3 times with a short pause between retries.
If all 3 HTTPS retries fail, automatically switch the remote to SSH:
https://github.com/user/repo.git → git@github.com:user/repo.gitgit remote set-url origin git@github.com:user/repo.gitIf the remote is already using SSH and the connection fails, retry up to 3 times, then report the error to the user.
If the push fails for other reasons (e.g., divergent histories, non-fast-forward), present the error to the user and ask: "普通推送失败,是否使用强制推送?这可能会覆盖远程仓库的历史。(y/n)"
git push -u origin <branch> --forceAfter a successful push:
Save the mapping — Update references/repo-map.json to record the current project path and its GitHub URL, so future pushes for this project won't need to ask for the URL again. Read the file, add or update the entry, and write it back. The key is the absolute path of the project directory, the value is the remote URL.
Confirm success — Report:
references/repo-map.json — Local path to GitHub URL mappings. Read this first to resolve the remote URL; update it after each successful push.After each execution of this Skill:
diary/YYYY-MM-DD.md.SKILL.md.