Create Private GitHub Repo
Private repositories are essential for protecting sensitive code and managing access control. This guide will show you how to create and manage private GitHub repositories effectively.
What You’ll Learn
- Creating private repositories
- Managing repository settings
- Access control
- Security best practices
- Repository management
Implementation Steps
-
Create Private Repository
# Create new repository on GitHub # Click "New repository" # Select "Private" # Initialize with README # Clone repository git clone https://github.com/username/private-repo.git # Verify remote git remote -v
- Create on GitHub
- Set visibility
- Initialize repo
- Clone locally
-
Configure Repository
# Set up Git config git config user.name "Your Name" git config user.email "your.email@example.com" # Create .gitignore touch .gitignore echo "node_modules/" >> .gitignore echo ".env" >> .gitignore # Initial commit git add . git commit -m "Initial commit" git push origin main
- Set configuration
- Add gitignore
- Make initial commit
- Push changes
-
Manage Access
# Add collaborator (on GitHub) # Settings > Collaborators > Add people # Verify access git ls-remote https://github.com/username/private-repo.git
- Add collaborators
- Set permissions
- Verify access
- Manage teams
-
Security Setup
# Enable branch protection # Settings > Branches > Add rule # Set up security alerts # Settings > Security & analysis
- Protect branches
- Enable alerts
- Set up scanning
- Configure security
Best Practices
-
Repository Setup
- Clear naming
- Good description
- Proper README
- License file
-
Access Control
- Minimal access
- Regular review
- Team management
- Permission audit
-
Security
- Branch protection
- Security scanning
- Secret management
- Regular updates
-
Maintenance
- Regular cleanup
- Documentation
- Issue tracking
- Version control
Common Use Cases
-
Team Project
# Create team # Settings > Teams > New team # Add team to repo # Settings > Collaborators > Add team
-
Client Project
# Create client branch git checkout -b client/project-name # Set up deployment # Settings > Deploy keys
-
Internal Tools
# Create tools branch git checkout -b tools/utility-name # Add documentation mkdir docs touch docs/README.md
-
Sensitive Data
# Add to .gitignore echo "secrets/" >> .gitignore echo "config.local.js" >> .gitignore # Use environment variables touch .env.example
Advanced Usage
-
Repository Templates
# Create template # Settings > Template repository # Use template # Click "Use this template"
-
Automated Workflows
# Set up GitHub Actions mkdir .github/workflows touch .github/workflows/main.yml
-
Branch Management
# Create development branch git checkout -b develop # Set up branch rules # Settings > Branches
-
Integration Setup
# Add webhook # Settings > Webhooks # Configure integrations # Settings > Integrations
Common Issues and Solutions
-
Access Problems
# Check permissions git ls-remote # Update credentials git config --global credential.helper store
-
Security Issues
# Rotate deploy keys # Settings > Deploy keys # Update access tokens # Settings > Developer settings
-
Repository Size
# Clean up history git gc --prune=now # Use Git LFS git lfs install
Conclusion
Private repositories are essential for:
- Protecting code
- Managing access
- Maintaining security
- Team collaboration
- Project organization
Next Steps
After setting up your private repository:
- Set up CI/CD
- Configure webhooks
- Add documentation
- Plan deployment