create-github
Version:
a command-line tool to quickly initialize a Git repository and push it to GitHub
117 lines (85 loc) • 3.75 kB
Markdown
# create-github
[](LICENSE)
`create-github` is a command-line tool to quickly initialize a Git repository and push it to GitHub. With simple interactive prompts, you can complete all steps from initializing the Git repository to pushing your code.
## Features
- Automatically generates a `.gitignore` file (if it doesn't exist).
- Supports interactive initialization of a Git repository (`git init`).
- Supports interactively adding files to the staging area (`git add .`).
- Supports interactively committing code (`git commit`).
- Supports setting up a remote repository address (`git remote add origin`).
- Supports pushing code to a specified branch (`git push -u origin <branch>`).
- Provides friendly command-line prompts and error handling.
- **Cross-platform support**: Automatically detects the operating system and generates appropriate Git commands for Windows (PowerShell) and Unix/Linux systems.
## Installation and Usage
### Option 1: Run Directly with `npm init`
You can use the following command to initialize a GitHub repository directly:
```bash
npm init github
```
This command will prompt you through the steps to initialize a Git repository and push it to GitHub.
### Option 2: Run Directly with `npm create`
Alternatively, you can use the shorter `npm create` syntax:
```bash
npm create github
```
This command works similarly to `npm init github` and provides the same functionality.
### Example
```bash
$ npm create github
Welcome to create-github - Quickly initialize a Git repository and push to GitHub
.gitignore file created successfully
Execute git init? (default: y): y
git init executed successfully
Execute git add .? (default: y): y
git add . executed successfully
Enter commit message (default: Initial commit): First commit
git commit executed successfully
Enter GitHub repository URL: https://github.com/your-repo.git
Enter branch name (default: main): main
git remote added successfully
Execute git push to main branch? (default: y): y
git push to main branch successful
Operation completed!
```
## Cross-Platform Support
The tool automatically detects the operating system and generates appropriate Git commands:
- **Windows**: Uses PowerShell commands.
- **Non-Windows**: Uses Unix/Linux shell commands.
For example, the following script is added to [package.json](file://d:\hub\代码测试\proj4ts\create-github\package.json):
```json
"scripts": {
"git": "powershell -Command \"$msg = Read-Host 'Enter commit message'; git add .; git commit -m \\\"$msg\\\"; git push\""
}
```
## Configuration File
The TypeScript configuration file [tsconfig.json](file://d:\hub\代码测试\proj4ts\create-github\tsconfig.json) contains the following settings:
```json
{
"compilerOptions": {
"target": "ES2020",
"module": "CommonJS",
"outDir": "./dist",
"rootDir": "./src",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"typeRoots": ["node_modules/@types"],
"forceConsistentCasingInFileNames": true
},
"include": ["src/**/*"],
"exclude": ["node_modules", "**/*.test.ts"]
}
```
Ensure that TypeScript and Node.js type definitions are installed correctly:
```bash
npm install --save-dev typescript @types/node
```
## Contribution Guidelines
We welcome issues and pull requests! If you'd like to contribute to the project, please follow these steps:
1. Fork this repository.
2. Create your feature branch (`git checkout -b feature/YourFeatureName`).
3. Commit your changes (`git commit -m 'Add some feature'`).
4. Push your branch (`git push origin feature/YourFeatureName`).
5. Submit a Pull Request.
## License
This project is licensed under the [MIT License](LICENSE).