Creating GitHub Repositories
This guide covers multiple methods for creating GitHub repositories, from manual web interface to automated API scripts.
Method 1: Create via Web Interface
Basic Steps
- Go to GitHub → Your profile → Repositories
- Click "New" button
- Fill in repository details:
- Repository name
- Description (optional)
- Public/Private
- Initialize with README (optional)
- Add .gitignore (optional)
- Choose license (optional)
- Click "Create repository"
Method 2: Create via API
Using cURL Command
# Read stored token
TOKEN=$(cat ~/.config/github/token)
# Create repository
curl -X POST -H "Authorization: token $TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/user/repos \
-d '{
"name": "vps-management",
"description": "VPS server management scripts and configurations",
"private": false,
"auto_init": false
}'
Repository Configuration Options
{
"name": "repository-name", // Required: Repository name
"description": "Description here", // Optional: Short description
"homepage": "https://example.com", // Optional: Project homepage
"private": false, // Boolean: Public or private
"has_issues": true, // Boolean: Enable issues
"has_projects": true, // Boolean: Enable projects
"has_wiki": true, // Boolean: Enable wiki
"auto_init": false, // Boolean: Create initial README
"gitignore_template": "Node", // Optional: .gitignore template
"license_template": "mit", // Optional: License template
"allow_squash_merge": true, // Boolean: Allow squash merging
"allow_merge_commit": true, // Boolean: Allow merge commits
"allow_rebase_merge": true // Boolean: Allow rebase merging
}
Method 3: Initialize Local Repository
Create and Push New Repository
# Navigate to project directory
cd /home/rezriz/github/01-production/vps-management
# Initialize git repository
git init
# Configure local git user
git config user.email "donnyaw@gmail.com"
git config user.name "donnyaw"
# Create README
echo "# VPS Management" > README.md
# Add files to staging
git add README.md
# Create initial commit
git commit -m "Initial commit"
# Add remote repository
git remote add origin git@github.com:donnyaw/vps-management.git
# Set main branch (modern Git standard)
git branch -M main
# Push to GitHub
git push -u origin main
Complete Setup in One Command
cd /home/rezriz/github/01-production/vps-management && \
git init && \
git config user.email "donnyaw@gmail.com" && \
git config user.name "donnyaw" && \
git remote add origin git@github.com:donnyaw/vps-management.git && \
git branch -M main && \
echo "# VPS Management" > README.md && \
git add README.md && \
git commit -m "Initial commit" && \
git push -u origin main
Real-World Examples from Bash History
Example 1: vps-management Repository
# Create repository via API first (see Method 2 above)
# Initialize and push
git init /home/rezriz/github/01-production/vps-management && \
cd /home/rezriz/github/01-production/vps-management && \
git remote add origin git@github.com:donnyaw/vps-management.git && \
git branch -M main && \
echo "# VPS Management" > README.md && \
git add README.md && \
git commit -m "Initial commit" && \
git push -u origin main
Example 2: docker Repository
# Navigate to directory
cd /home/rezriz/github/01-production/vps-management/Docker
# Initialize repository
git init
git remote add origin git@github.com:donnyaw/docker.git
git config user.email "donnyaw@gmail.com"
git config user.name "donnyaw"
# Create main branch
git checkout -b main
# Add all files
git add .
# Commit
git commit -m "Initialize Docker repository"
# Force push (first push to empty repo)
git push -u origin main -f
Example 3: vps-transfer-toolkit Repository
cd /home/rezriz/github/03-lab/AI-Agent/transfer-to-another-vps
# Initialize and configure
git init
git config user.name "rezriz"
git config user.email "donnyaw@gmail.com"
# Stage files
git add .
git status
# Commit with detailed message
git commit -m "Initial commit: VPS transfer scripts with SCP, Rsync, and Rclone support"
# Add remote (repository created via API)
git remote add origin git@github.com:donnyaw/vps-transfer-toolkit.git
# Set branch and push
git branch -M main
git push -u origin main
Example 4: restic-rclone Repository
# Clone existing repository
cd /home/rezriz/github
git clone https://github.com/donnyaw/restic-rclone.git
# Navigate to repo
cd /home/rezriz/github/restic-rclone
# Make changes and stage
git add .
# Push with specific SSH key
GIT_SSH_COMMAND="ssh -i /home/rezriz/.ssh/github/id_ed25519 -o IdentitiesOnly=yes" git push origin main
Managing Repository Structure
Move Repository Location
# Move Docker folder to production
mv /home/rezriz/github/01-production/vps-management/Docker \
/home/rezriz/github/01-production/docker
# Update parent repository (remove moved folder)
cd /home/rezriz/github/01-production/vps-management
git rm -r Docker
git commit -m "Remove Docker folder (moved to its own repository)"
git push
Migrate Content Between Repositories
# Copy from lab to production
mkdir -p /home/rezriz/github/01-production/Docker
cp -rv /home/rezriz/github/03-lab/docker/* /home/rezriz/github/01-production/Docker/
cp -rv /home/rezriz/github/03-lab/docker/.* /home/rezriz/github/01-production/Docker/ 2>/dev/null || true
# Commit to new repository
cd /home/rezriz/github/01-production/vps-management
git add .
git commit -m "Migrate Docker deployment and app configurations from lab to production"
git push
Handling Remote Repository Issues
Fix "Failed to Push" Errors
cd /home/rezriz/github/01-production/vps-management
# Pull with rebase (if remote has commits)
git pull origin main --rebase
git push -u origin main
Force Reset to Remote
cd /home/rezriz/github/01-production/vps-management
# Abort any ongoing rebase
git rebase --abort
# Fetch latest from remote
git fetch origin
# Hard reset to match remote
git reset --hard origin/main
# Add your changes
echo "# VPS Management" > README.md
git add README.md
# Amend commit
git commit --amend --no-edit
# Force push
git push -f origin main
Set Upstream Branch
cd /home/rezriz/github/01-production/vps-management
git push --set-upstream origin main
Repository Naming Conventions
Our Project Structure
~/github/
01-production/ # Production-ready code
vps-management/ # VPS scripts and configs
docker/ # Docker deployments
vps-transfer-toolkit/ # Transfer tools
02-common/ # Shared resources
ssh/ # SSH configurations
03-lab/ # Experimental/development
AI-Agent/ # AI-assisted projects
docker-data-backup/ # Backup scripts
Config-Backups/ # Configuration backups
Naming Best Practices
- Use kebab-case:
vps-managementnotVPS_Management - Be descriptive:
vps-transfer-toolkitclearly states purpose - Avoid special characters: Only use
-(hyphen) - Keep it concise: Max 30-40 characters
- Use prefixes for grouping:
docker-*for Docker-related reposvps-*for VPS toolsbackup-*for backup scripts
Common Commands Reference
Repository Information
# View remote URLs
git remote -v
# Check repository status
git status
# View commit history
git log -1
# Check branch
git branch
# View all branches
git branch -a
Clean Up Lab Repositories
# Remove experimental directory after migration
rm -rf /home/rezriz/github/03-lab/docker
# Verify cleanup
ls -la /home/rezriz/github/03-lab/
Verify Repository State
# Check for nested .git directories (avoid)
ls -la /home/rezriz/github/01-production/vps-management/Docker/.git 2>/dev/null || echo "No nested git"
# List all repositories
ls -F /home/rezriz/github/
Troubleshooting
Issue: Repository Already Exists
# Remove existing remote
git remote remove origin
# Add correct remote
git remote add origin git@github.com:donnyaw/repository-name.git
Issue: Large Initial Commit
# Check what's being committed
git status
# Show file sizes
git ls-files | xargs du -h | sort -h | tail -20
# Remove large files from staging
git reset HEAD large-file.zip
Issue: Wrong User Configuration
# Set local repository user (overrides global)
git config user.email "donnyaw@gmail.com"
git config user.name "donnyaw"
# Verify configuration
git config --list --local
Automation Script
Complete Repository Setup Script
#!/bin/bash
# create-and-push-repo.sh
REPO_NAME="$1"
DESCRIPTION="${2:-Created via automation script}"
PRIVATE="${3:-false}"
LOCAL_PATH="${4:-/home/rezriz/github/01-production/$REPO_NAME}"
if [ -z "$REPO_NAME" ]; then
echo "Usage: $0 <repo-name> [description] [private] [local-path]"
exit 1
fi
# Create repository via API
TOKEN=$(cat ~/.config/github/token)
curl -X POST -H "Authorization: token $TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/user/repos \
-d "{
\"name\": \"$REPO_NAME\",
\"description\": \"$DESCRIPTION\",
\"private\": $PRIVATE
}"
# Initialize local repository
mkdir -p "$LOCAL_PATH"
cd "$LOCAL_PATH"
git init
git config user.email "donnyaw@gmail.com"
git config user.name "donnyaw"
echo "# $REPO_NAME" > README.md
git add README.md
git commit -m "Initial commit"
git remote add origin "git@github.com:donnyaw/$REPO_NAME.git"
git branch -M main
git push -u origin main
echo " Repository created and pushed: https://github.com/donnyaw/$REPO_NAME"