-
Notifications
You must be signed in to change notification settings - Fork 0
Claude/create GitHub repo script 011 cu nuk t zx7fg hk1jh5 fg ax #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Claude/create GitHub repo script 011 cu nuk t zx7fg hk1jh5 fg ax #1
Conversation
Add a bash script that automates the process of: - Creating a new directory - Initializing a git repository - Creating a public GitHub repository using gh CLI - Configuring the remote origin - Setting up main branch tracking Usage: scripts/create-github-repo.sh <repo-name> [description] 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Remove the explicit git branch --set-upstream-to command as it fails when the remote branch doesn't exist yet. The git push -u command already sets up tracking automatically. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
- Create create-github-repo-function.sh with a shell function version - Add sourcing of the function to .zshrc - Function keeps you in the newly created directory after completion - Use: create-github-repo <repo-name> [description] This solves the issue where the standalone script returns to the original directory after execution. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds automation for creating GitHub repositories directly from the command line. It introduces both a standalone script and a shell function that create a local directory, initialize a git repository, and create a corresponding GitHub repository using the GitHub CLI.
Key changes:
- Added a bash script for creating GitHub repositories with automatic initialization
- Added a shell function variant that keeps the user in the newly created directory
- Integrated the function into the zsh configuration for convenient access
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| zsh/.zshrc | Sources the GitHub repo creation function to make it available in shell sessions |
| scripts/create-github-repo.sh | Standalone script for creating GitHub repositories with git initialization |
| scripts/create-github-repo-function.sh | Shell function version that maintains current directory context after execution |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| git init -b main || { cd ..; return 1; } | ||
| echo "# $REPO_NAME" > README.md | ||
|
|
||
| # Create initial commit | ||
| git add README.md | ||
| git commit -m "Initial commit" || { cd ..; return 1; } | ||
|
|
||
| # Create GitHub repository (public) | ||
| echo "Creating public GitHub repository..." | ||
| if [ -n "$REPO_DESC" ]; then | ||
| gh repo create "$REPO_NAME" --public --source=. --remote=origin --description "$REPO_DESC" || { cd ..; return 1; } | ||
| else | ||
| gh repo create "$REPO_NAME" --public --source=. --remote=origin || { cd ..; return 1; } | ||
| fi | ||
|
|
||
| # Push to GitHub (this also sets up tracking) | ||
| git push -u origin main || { cd ..; return 1; } |
Copilot
AI
Oct 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error handler cd .. navigates to the parent directory but leaves the newly created empty directory behind. This cleanup is incomplete and will leave orphaned directories when git init fails. Consider adding rm -rf \"$REPO_NAME\" before the cd .. to fully clean up on failure.
| git init -b main || { cd ..; return 1; } | |
| echo "# $REPO_NAME" > README.md | |
| # Create initial commit | |
| git add README.md | |
| git commit -m "Initial commit" || { cd ..; return 1; } | |
| # Create GitHub repository (public) | |
| echo "Creating public GitHub repository..." | |
| if [ -n "$REPO_DESC" ]; then | |
| gh repo create "$REPO_NAME" --public --source=. --remote=origin --description "$REPO_DESC" || { cd ..; return 1; } | |
| else | |
| gh repo create "$REPO_NAME" --public --source=. --remote=origin || { cd ..; return 1; } | |
| fi | |
| # Push to GitHub (this also sets up tracking) | |
| git push -u origin main || { cd ..; return 1; } | |
| git init -b main || { cd ..; rm -rf "$REPO_NAME"; return 1; } | |
| echo "# $REPO_NAME" > README.md | |
| # Create initial commit | |
| git add README.md | |
| git commit -m "Initial commit" || { cd ..; rm -rf "$REPO_NAME"; return 1; } | |
| # Create GitHub repository (public) | |
| echo "Creating public GitHub repository..." | |
| if [ -n "$REPO_DESC" ]; then | |
| gh repo create "$REPO_NAME" --public --source=. --remote=origin --description "$REPO_DESC" || { cd ..; rm -rf "$REPO_NAME"; return 1; } | |
| else | |
| gh repo create "$REPO_NAME" --public --source=. --remote=origin || { cd ..; rm -rf "$REPO_NAME"; return 1; } | |
| fi | |
| # Push to GitHub (this also sets up tracking) | |
| git push -u origin main || { cd ..; rm -rf "$REPO_NAME"; return 1; } |
|
|
||
| # Create initial commit | ||
| git add README.md | ||
| git commit -m "Initial commit" || { cd ..; return 1; } |
Copilot
AI
Oct 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All error handlers use cd .. which leaves the failed repository directory and potentially a remote GitHub repository in an inconsistent state. The cleanup is incomplete - the local directory remains, and if gh repo create succeeded but git push failed, the remote repository also remains. Consider comprehensive cleanup that removes the local directory and potentially the remote repository on failure.
| gh repo create "$REPO_NAME" --public --source=. --remote=origin --description "$REPO_DESC" || { cd ..; return 1; } | ||
| else | ||
| gh repo create "$REPO_NAME" --public --source=. --remote=origin || { cd ..; return 1; } |
Copilot
AI
Oct 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All error handlers use cd .. which leaves the failed repository directory and potentially a remote GitHub repository in an inconsistent state. The cleanup is incomplete - the local directory remains, and if gh repo create succeeded but git push failed, the remote repository also remains. Consider comprehensive cleanup that removes the local directory and potentially the remote repository on failure.
| fi | ||
|
|
||
| # Push to GitHub (this also sets up tracking) | ||
| git push -u origin main || { cd ..; return 1; } |
Copilot
AI
Oct 22, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All error handlers use cd .. which leaves the failed repository directory and potentially a remote GitHub repository in an inconsistent state. The cleanup is incomplete - the local directory remains, and if gh repo create succeeded but git push failed, the remote repository also remains. Consider comprehensive cleanup that removes the local directory and potentially the remote repository on failure.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
No description provided.