From cdecee2840ec5ee7301c130afe2aff3f56e55853 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 22 Oct 2025 21:01:44 +0000 Subject: [PATCH 1/5] Add script to create GitHub repositories MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 [description] 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- scripts/create-github-repo.sh | 63 +++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100755 scripts/create-github-repo.sh diff --git a/scripts/create-github-repo.sh b/scripts/create-github-repo.sh new file mode 100755 index 0000000..b6031a9 --- /dev/null +++ b/scripts/create-github-repo.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env bash + +# Script to create a new directory, initialize git, and create a GitHub repository +# Usage: create-github-repo.sh [description] + +set -e # Exit on error + +# Check if gh CLI is installed +if ! command -v gh &> /dev/null; then + echo "Error: GitHub CLI (gh) is not installed" + echo "Install it from: https://cli.github.com/" + exit 1 +fi + +# Check if repo name is provided +if [ -z "$1" ]; then + echo "Usage: $0 [description]" + echo "Example: $0 my-new-project 'A cool new project'" + exit 1 +fi + +REPO_NAME="$1" +REPO_DESC="${2:-}" + +# Check if directory already exists +if [ -d "$REPO_NAME" ]; then + echo "Error: Directory '$REPO_NAME' already exists" + exit 1 +fi + +echo "Creating new repository: $REPO_NAME" + +# Create directory and cd into it +mkdir "$REPO_NAME" +cd "$REPO_NAME" + +# Initialize git repository +git init -b main +echo "# $REPO_NAME" > README.md + +# Create initial commit +git add README.md +git commit -m "Initial commit" + +# 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" +else + gh repo create "$REPO_NAME" --public --source=. --remote=origin +fi + +# Set up main branch tracking +git branch --set-upstream-to=origin/main main + +# Push to GitHub +git push -u origin main + +echo "" +echo "✓ Repository created successfully!" +echo " Local path: $(pwd)" +echo " Remote URL: $(git remote get-url origin)" +echo "" From 4700358ddd066cc0277cd407ca01e0e9f02202d3 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 22 Oct 2025 21:28:39 +0000 Subject: [PATCH 2/5] Fix branch tracking issue in create-github-repo script MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- scripts/create-github-repo.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/scripts/create-github-repo.sh b/scripts/create-github-repo.sh index b6031a9..070dfc6 100755 --- a/scripts/create-github-repo.sh +++ b/scripts/create-github-repo.sh @@ -50,10 +50,7 @@ else gh repo create "$REPO_NAME" --public --source=. --remote=origin fi -# Set up main branch tracking -git branch --set-upstream-to=origin/main main - -# Push to GitHub +# Push to GitHub (this also sets up tracking) git push -u origin main echo "" From 777a8f132f35f17b2423c887e36e23f120f36b8a Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 22 Oct 2025 21:32:29 +0000 Subject: [PATCH 3/5] Add shell function to stay in directory after repo creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 [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 --- scripts/create-github-repo-function.sh | 65 ++++++++++++++++++++++++++ zsh/.zshrc | 3 ++ 2 files changed, 68 insertions(+) create mode 100644 scripts/create-github-repo-function.sh diff --git a/scripts/create-github-repo-function.sh b/scripts/create-github-repo-function.sh new file mode 100644 index 0000000..f4d7046 --- /dev/null +++ b/scripts/create-github-repo-function.sh @@ -0,0 +1,65 @@ +#!/usr/bin/env bash + +# Shell function to create a new directory, initialize git, and create a GitHub repository +# This function keeps you in the newly created directory after completion +# +# To use this function, add to your .zshrc or .bashrc: +# source ~/dotfiles/scripts/create-github-repo-function.sh +# +# Usage: create-github-repo [description] + +create-github-repo() { + # Check if gh CLI is installed + if ! command -v gh &> /dev/null; then + echo "Error: GitHub CLI (gh) is not installed" + echo "Install it from: https://cli.github.com/" + return 1 + fi + + # Check if repo name is provided + if [ -z "$1" ]; then + echo "Usage: create-github-repo [description]" + echo "Example: create-github-repo my-new-project 'A cool new project'" + return 1 + fi + + local REPO_NAME="$1" + local REPO_DESC="${2:-}" + + # Check if directory already exists + if [ -d "$REPO_NAME" ]; then + echo "Error: Directory '$REPO_NAME' already exists" + return 1 + fi + + echo "Creating new repository: $REPO_NAME" + + # Create directory and cd into it + mkdir "$REPO_NAME" || return 1 + cd "$REPO_NAME" || return 1 + + # Initialize git repository + 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; } + + echo "" + echo "✓ Repository created successfully!" + echo " Local path: $(pwd)" + echo " Remote URL: $(git remote get-url origin)" + echo "" +} diff --git a/zsh/.zshrc b/zsh/.zshrc index 3537157..1731f0d 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -186,4 +186,7 @@ alias pylist='pyenv versions' # Show current Python version alias pyversion='python --version' +# GitHub repository creation function +[ -f "$HOME/dotfiles/scripts/create-github-repo-function.sh" ] && source "$HOME/dotfiles/scripts/create-github-repo-function.sh" + . "$HOME/.turso/env" From d024b4abd1feabb124ac4ea32c1d4918f866b296 Mon Sep 17 00:00:00 2001 From: Martin Palastanga Date: Wed, 22 Oct 2025 23:01:20 +0100 Subject: [PATCH 4/5] Update scripts/create-github-repo.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- scripts/create-github-repo.sh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/scripts/create-github-repo.sh b/scripts/create-github-repo.sh index 070dfc6..49b15f2 100755 --- a/scripts/create-github-repo.sh +++ b/scripts/create-github-repo.sh @@ -35,7 +35,18 @@ mkdir "$REPO_NAME" cd "$REPO_NAME" # Initialize git repository -git init -b main +# Check git version and use appropriate init syntax +GIT_VERSION=$(git --version | awk '{print $3}') +# Function to compare versions: returns 0 if $1 >= $2 +version_ge() { + [ "$(printf '%s\n' "$2" "$1" | sort -V | head -n1)" = "$2" ] +} +if version_ge "$GIT_VERSION" "2.28.0"; then + git init -b main +else + git init + git branch -m main +fi echo "# $REPO_NAME" > README.md # Create initial commit From b398a61e4e8290ef8f751d9282b1a4f334e1dea6 Mon Sep 17 00:00:00 2001 From: Martin Palastanga Date: Wed, 22 Oct 2025 23:01:46 +0100 Subject: [PATCH 5/5] Update scripts/create-github-repo-function.sh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- scripts/create-github-repo-function.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/create-github-repo-function.sh b/scripts/create-github-repo-function.sh index f4d7046..05401a7 100644 --- a/scripts/create-github-repo-function.sh +++ b/scripts/create-github-repo-function.sh @@ -39,23 +39,23 @@ create-github-repo() { cd "$REPO_NAME" || return 1 # Initialize git repository - git init -b 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 ..; return 1; } + 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 ..; return 1; } + 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 ..; return 1; } + 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 ..; return 1; } + git push -u origin main || { cd ..; rm -rf "$REPO_NAME"; return 1; } echo "" echo "✓ Repository created successfully!"