Skip to content

Claude/create GitHub repo script 011 cu nuk t zx7fg hk1jh5 fg ax#1

Open
Martz wants to merge 5 commits into
mainfrom
claude/create-github-repo-script-011CUNukTZx7fgHK1jh5FGAx
Open

Claude/create GitHub repo script 011 cu nuk t zx7fg hk1jh5 fg ax#1
Martz wants to merge 5 commits into
mainfrom
claude/create-github-repo-script-011CUNukTZx7fgHK1jh5FGAx

Conversation

@Martz
Copy link
Copy Markdown
Owner

@Martz Martz commented Oct 22, 2025

No description provided.

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>
@Martz Martz requested a review from Copilot October 22, 2025 21:36
Copy link
Copy Markdown

Copilot AI left a 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.

Comment thread scripts/create-github-repo.sh Outdated
Comment thread scripts/create-github-repo-function.sh Outdated
Comment on lines +42 to +58
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; }
Copy link

Copilot AI Oct 22, 2025

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.

Suggested change
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; }

Copilot uses AI. Check for mistakes.
Comment thread scripts/create-github-repo-function.sh Outdated

# Create initial commit
git add README.md
git commit -m "Initial commit" || { cd ..; return 1; }
Copy link

Copilot AI Oct 22, 2025

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.

Copilot uses AI. Check for mistakes.
Comment thread scripts/create-github-repo-function.sh Outdated
Comment on lines +52 to +54
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; }
Copy link

Copilot AI Oct 22, 2025

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.

Copilot uses AI. Check for mistakes.
Comment thread scripts/create-github-repo-function.sh Outdated
fi

# Push to GitHub (this also sets up tracking)
git push -u origin main || { cd ..; return 1; }
Copy link

Copilot AI Oct 22, 2025

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.

Copilot uses AI. Check for mistakes.
Martz and others added 2 commits October 22, 2025 23:01
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants