Skip to content
/ gprsa Public

Automate GitHub private repository setup with Python. Streamline project initialization, .gitignore management, and initial commits. Save time and ensure consistency across multiple projects.

Notifications You must be signed in to change notification settings

reegen66/gprsa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

30 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Automated GitHub Private Project/Repository Setup/Creator/Automator

This powerful Python script automates the process of setting up a new GitHub repository, making it easier than ever to start a new coding project. Whether you're a seasoned developer or just starting out, this tool streamlines your workflow by handling repository creation, Git initialization, and initial commits all in one go.

One line command quick start:

curl -sSL https://raw.githubusercontent.com/reegen66/gprsa/main/setup.sh -o setup.sh && bash setup.sh

GitHub Private Repository Setup Automator

What it does

This Python script automates the entire process of setting up a new private GitHub project:

  1. Creates a new private GitHub repository with a name you specify.
  2. Initializes Git in your local project directory.
  3. Sets up remote origin and links it to the new GitHub repository.
  4. Downloads a language-specific .gitignore template file (Python or Node.js).
  5. Allows you to add custom entries to the .gitignore file.
  6. Performs an initial commit with all your project files.
  7. Pushes the commit to the new GitHub repository.

All of this is done automatically with minimal user input, saving you time and ensuring a consistent setup process.

Quick Example

$ ./github_setup.py
Enter the project language (python/node): python
Enter the project name for GitHub: my-awesome-project
# ... [Script creates repo, initializes Git, sets up .gitignore, commits, and pushes]
Repository created: https://github.com/yourusername/my-awesome-project.git

In just a few seconds, your local project is set up, committed, and pushed to a new private GitHub repository!


Features

  • πŸš€ Automatically creates a new private GitHub repository
  • πŸ”§ Initializes Git locally and sets up remote origin
  • πŸ“ Downloads language-specific .gitignore files (Python or Node.js)
  • πŸ”’ Securely handles GitHub authentication using personal access tokens
  • 🧹 Option to clean existing Git files for a fresh start
  • ✏️ Allows adding custom entries to .gitignore
  • πŸ”„ Performs initial commit and push to the new repository

Prerequisites

Before you begin, ensure you have the following installed:

  • Python 3.6 or higher
  • pip (Python package manager)

Quick Start

To get started with the GitHub Project Setup Script, follow these steps:

  1. One line command:
curl -sSL https://raw.githubusercontent.com/reegen66/gprsa/main/setup.sh -o setup.sh && bash setup.sh

Or step by syep

  1. Download the script using wget:
wget https://raw.githubusercontent.com/reegen66/gprsa/main/github_setup.py
  1. Install the required Python packages:
pip install requests python-dotenv
  1. Create a .gprsa file in the same directory as the script with the following content:
GITHUB_TOKEN=your_personal_access_token_here
[email protected]

Replace your_personal_access_token_here with your GitHub personal access token and [email protected] with your GitHub email address.

  1. Make the script executable:
chmod  x github_setup.py
  1. Run the script:
./github_setup.py

Usage

When you run the script, it will guide you through the following steps:

  1. If an existing Git repository is detected, it will ask if you want to delete it and start fresh.
  2. You'll be prompted to choose the project language (Python or Node.js).
  3. The script will download the appropriate .gitignore file for your chosen language.
  4. You'll have the option to add custom lines to the .gitignore file.
  5. You'll be asked to enter a name for your new GitHub repository.
  6. The script will create the repository, initialize Git, and push the initial commit.

Creating a GitHub Personal Access Token

To use this script, you need to create a GitHub Personal Access Token with the correct permissions. Follow these steps:

  1. Log in to your GitHub account.
  2. Click on your profile picture in the top-right corner and select "Settings" from the dropdown menu.
  3. In the left sidebar, click on "Developer settings".
  4. In the new left sidebar, click on "Personal access tokens".
  5. Click on "Generate new token" (or "Generate new token (classic)" if you see that option).
  6. Give your token a descriptive name, e.g., "GitHub Project Setup Script".
  7. Set the expiration as per your preference. For security reasons, it's recommended to set an expiration date.
  8. Select the following scopes (permissions):
    • repo (Full control of private repositories)
      • This allows the script to create and manage repositories.
    • admin:public_key (Manage your public keys)
      • This allows the script to add deploy keys to your repositories if needed.
  9. Scroll to the bottom and click "Generate token".
  10. Important: Copy the generated token immediately and store it securely. You won't be able to see it again!

Once you have your token, add it to your .gprsa file like this:

GITHUB_TOKEN=your_generated_token_here
[email protected]

Replace your_generated_token_here with the actual token you just created, and [email protected] with the email associated with your GitHub account.

Security Note: Never share your personal access token or commit it to a repository. The .gprsa file is included in the .gitignore to prevent accidental exposure of your token.

Cloning Private Repositories

This script streamlines the process of cloning private GitHub repositories while maintaining security and handling potential conflicts. Here's how it works:

Features

  • Secure Authentication: Uses your GitHub token stored in .gprsa for authentication, ensuring secure access to private repositories.
  • Temporary Directory Cloning: Clones the repository to a temporary directory first, preventing conflicts with existing files.
  • Conflict Resolution: Automatically handles potential conflicts with existing files and directories.
  • Environment File Handling: Renames any .env file from the cloned repository to .env_repo to avoid overwriting your local configuration.
  • Git Configuration: Sets up the local git configuration with your email and username.

Process

  1. User Input: You'll be prompted to enter the URL of the private repository you want to clone.

  2. Secure Cloning: The script uses your GitHub token from .gprsa to clone the repository into a temporary directory.

  3. File Transfer: Contents from the cloned repository are carefully moved to your current directory:

    • Existing .git directory is removed to avoid conflicts.
    • Any .env file from the repository is renamed to .env_repo.
    • Other files are moved, replacing any existing files with the same name.
  4. Git Setup: The script sets up the local git configuration using your GitHub email.

  5. Completion: Once the process is complete, you'll have a fully functional local copy of the private repository, ready for development.

Benefits

  • Simplicity: Clone private repositories with a single command, no need to manually handle authentication or potential conflicts.
  • Security: Your GitHub token is never exposed in plain text during the process.
  • Consistency: Ensures a consistent setup process across different machines or team members.
  • Local Config Preservation: Keeps your local .gprsa and .env files intact, preserving your local settings and authentication.

By using this script to clone private repositories, you can quickly set up your development environment while maintaining security and avoiding common pitfalls in the process.

Why This Is Useful

Setting up a new private GitHub repository and establishing the initial connection can be a time-consuming and error-prone process, especially for developers working on multiple projects or teams managing numerous repositories. This script addresses several common pain points:

Common Challenges in Manual Setup

  1. SSH Key Management: Generating, adding, and managing SSH keys for each new repository can be confusing, especially for those new to Git.

  2. Authentication Issues: Dealing with authentication errors due to misconfigured credentials or expired tokens is frustrating and time-consuming.

  3. Repository Initialization: Manually creating a repository on GitHub, then initializing it locally and linking the two can involve multiple steps where errors can occur.

  4. Gitignore Configuration: Forgetting to add a .gitignore file or manually copying appropriate rules for each project type leads to cluttered repositories and accidental commits of unwanted files.

  5. Inconsistent Setup: When working across multiple projects or with a team, ensuring consistent repository structure and initial configuration can be challenging.

  6. Token and Credential Handling: Securely managing and using personal access tokens or other credentials across different environments and projects can be risky and complex.

  7. Project-Specific Configurations: Setting up project-specific Git configurations (like user email) for each new repository is often overlooked in manual setups.

Time Savings

The time savings provided by this script are substantial:

  • Manual Setup: On average, manually setting up a new private GitHub repository, including creating SSH keys, configuring Git, setting up .gitignore, and making the initial commit, can take anywhere from 15 to 30 minutes, depending on experience and potential troubleshooting.

  • Automated Setup: With this script, the entire process is reduced to about 2-3 minutes, mostly spent on user input and API interactions.

Time Saved per Year

Let's consider a scenario where a developer or team sets up 1000 new projects in a year:

  • Manual Setup: 1000 projects Γ— 20 minutes (average) = 333.33 hours or about 42 working days
  • Automated Setup: 1000 projects Γ— 2.5 minutes = 41.67 hours or about 5 working days

Total Time Saved: 37 working days per year

This significant time saving allows developers to focus on actual coding and project development rather than repetitive setup tasks. Moreover, the consistency and reliability provided by the automated setup reduce errors and improve overall project management.

Additional Benefits

  • Consistent Best Practices: Ensures that every project starts with proper Git configuration and appropriate .gitignore files.
  • Easy Customization: The script can be easily modified to accommodate team-specific needs or additional setup steps.
  • Learning Tool: For newcomers to Git and GitHub, the script serves as a practical example of automation and best practices in repository management.

By automating the GitHub project setup process, this script not only saves a tremendous amount of time but also ensures consistency, reduces errors, and allows developers to focus on what truly matters – writing great code.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.

Keywords

GitHub automation, repository setup, Git initialization, Python script, Node.js projects, developer workflow, project management, version control, .gitignore management, GitHub API


Credits: https://bizigniter.io Happy coding! πŸŽ‰

About

Automate GitHub private repository setup with Python. Streamline project initialization, .gitignore management, and initial commits. Save time and ensure consistency across multiple projects.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published