A bash script to create and push to a new GitHub repository directly from the command line. It automates the entire workflow: creating the remote repository, initializing git locally, and pushing your code.
- π Creates GitHub repositories via the GitHub API
- π Supports both private (default) and public repositories
- π¨ Color-coded output for better readability
- β Comprehensive error handling and validation
- π Token-based authentication (secure, follows GitHub best practices)
- π Auto-generates README.md if not present
- πΏ Uses modern
mainbranch naming - π Cross-platform browser opening support
- βοΈ Configurable via git config
- Git: Must be installed and accessible from command line
- Windows: Install Git for Windows (includes Git Bash and curl)
- Linux/macOS: Usually pre-installed, or install via package manager
- curl: Required for API calls (included with Git for Windows, pre-installed on Linux/macOS)
- GitHub Account: You need a GitHub account and personal access token
- Bash shell: Git Bash on Windows, or native bash on Linux/macOS
# Clone the repository
git clone https://github.com/yourusername/gitcreate.git
# Copy to your PATH
sudo cp gitcreate/gitcreate /usr/local/bin/
# Make it executable
sudo chmod +x /usr/local/bin/gitcreateRecommended Method (works perfectly with VS Code's integrated terminal):
# Clone the repository
git clone https://github.com/yourusername/gitcreate.git
cd gitcreate
# Create a bin directory in your home folder
mkdir -p ~/bin
# Copy the script there
cp gitcreate ~/bin/
chmod +x ~/bin/gitcreate
# Add to PATH (add this line to ~/.bashrc or ~/.bash_profile)
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrc
# Reload your shell
source ~/.bashrcQuick Method (run from current directory without installation):
cd /path/to/your/project
/path/to/gitcreate/gitcreateVS Code Note: Make sure your integrated terminal is set to "Git Bash". You can check/change this by:
- Open VS Code terminal
- Click the dropdown next to the + icon
- Select "Git Bash" as default profile
Important for Windows: If you edit the script file on Windows, make sure it has Unix line endings (LF, not CRLF). In VS Code, check the bottom-right corner and click "CRLF" to change it to "LF", or run:
sed -i 's/\r$//' ~/bin/gitcreateSimply download the gitcreate file and place it anywhere in your system's PATH.
Before using gitcreate, you need to configure your GitHub credentials:
git config --global github.user YOUR_GITHUB_USERNAME- Go to GitHub Settings β Tokens
- Click "Generate new token (classic)"
- Give it a descriptive name (e.g., "gitcreate script")
- Select the following scopes:
- β
repo(Full control of private repositories) - β
user(Read user profile data)
- β
- Click "Generate token" and copy the token
- Configure it in git:
git config --global github.token YOUR_PERSONAL_ACCESS_TOKENSecurity Note: Personal access tokens are more secure than passwords and can be easily revoked. Never share your token or commit it to a repository.
Navigate to your project directory and run:
gitcreategitcreate [OPTIONS]
Options:
-h, --help Show help message
-p, --public Create a public repository (default: private)cd my-project
gitcreatecd my-open-source-project
gitcreate --publicThe script will interactively ask you for:
- Repository name (defaults to current directory name)
- Repository description (optional)
- Confirmation before creating
- Open in browser after successful creation
- β Validates that Git and curl are installed
- β Checks for GitHub credentials (username and token)
- β Prompts for repository name, description, and visibility
- β Creates the repository on GitHub via API
- β Creates a README.md file if it doesn't exist
- β Initializes Git repository (if not already initialized)
- β Commits all files
- β
Renames branch to
main(if needed) - β Adds remote origin
- β Pushes code to GitHub
- β Optionally opens the repository in your browser
git config --global github.user YOUR_GITHUB_USERNAMEgit config --global github.token YOUR_PERSONAL_ACCESS_TOKEN- Check that your token has the correct scopes (
repo,user) - Verify the repository name is valid (letters, numbers, hyphens, underscores, periods)
- Ensure a repository with that name doesn't already exist in your account
- Check your internet connection
- Verify your token has
reposcope - Try pushing manually:
git push -u origin main
- π Never commit your GitHub token to a repository
- π Rotate tokens periodically
- ποΈ Revoke tokens you no longer need
- ποΈ Use tokens with minimal required scopes
- π» Consider using different tokens for different machines/purposes
Linux/macOS:
sudo rm /usr/local/bin/gitcreate
git config --global --unset github.user
git config --global --unset github.tokenWindows:
rm ~/bin/gitcreate
git config --global --unset github.user
git config --global --unset github.tokenContributions are welcome! Feel free to submit issues or pull requests.
This project is provided as-is under the MIT License.
- Original inspiration: robwierzbowski's gist
- Improved and enhanced with modern GitHub API practices