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
This Python script automates the entire process of setting up a new private GitHub project:
- Creates a new private GitHub repository with a name you specify.
- Initializes Git in your local project directory.
- Sets up remote origin and links it to the new GitHub repository.
- Downloads a language-specific
.gitignore
template file (Python or Node.js). - Allows you to add custom entries to the
.gitignore
file. - Performs an initial commit with all your project files.
- 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.
$ ./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!
- 🚀 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
Before you begin, ensure you have the following installed:
- Python 3.6 or higher
pip
(Python package manager)
To get started with the GitHub Project Setup Script, follow these steps:
- One line command:
curl -sSL https://raw.githubusercontent.com/reegen66/gprsa/main/setup.sh -o setup.sh && bash setup.sh
Or step by syep
- Download the script using
wget
:
wget https://raw.githubusercontent.com/reegen66/gprsa/main/github_setup.py
- Install the required Python packages:
pip install requests python-dotenv
- Create a
.gprsa
file in the same directory as the script with the following content:
GITHUB_TOKEN=your_personal_access_token_here
GITHUB_EMAIL=your_github_email@example.com
Replace your_personal_access_token_here
with your GitHub personal access token and your_github_email@example.com
with your GitHub email address.
- Make the script executable:
chmod +x github_setup.py
- Run the script:
./github_setup.py
When you run the script, it will guide you through the following steps:
- If an existing Git repository is detected, it will ask if you want to delete it and start fresh.
- You'll be prompted to choose the project language (Python or Node.js).
- The script will download the appropriate
.gitignore
file for your chosen language. - You'll have the option to add custom lines to the
.gitignore
file. - You'll be asked to enter a name for your new GitHub repository.
- The script will create the repository, initialize Git, and push the initial commit.
To use this script, you need to create a GitHub Personal Access Token with the correct permissions. Follow these steps:
- Log in to your GitHub account.
- Click on your profile picture in the top-right corner and select "Settings" from the dropdown menu.
- In the left sidebar, click on "Developer settings".
- In the new left sidebar, click on "Personal access tokens".
- Click on "Generate new token" (or "Generate new token (classic)" if you see that option).
- Give your token a descriptive name, e.g., "GitHub Project Setup Script".
- Set the expiration as per your preference. For security reasons, it's recommended to set an expiration date.
- 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.
- Scroll to the bottom and click "Generate token".
- 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
GITHUB_EMAIL=your_github_email@example.com
Replace your_generated_token_here
with the actual token you just created, and your_github_email@example.com
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.
This script streamlines the process of cloning private GitHub repositories while maintaining security and handling potential conflicts. Here's how it works:
- 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.
-
User Input: You'll be prompted to enter the URL of the private repository you want to clone.
-
Secure Cloning: The script uses your GitHub token from
.gprsa
to clone the repository into a temporary directory. -
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.
- Existing
-
Git Setup: The script sets up the local git configuration using your GitHub email.
-
Completion: Once the process is complete, you'll have a fully functional local copy of the private repository, ready for development.
- 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.
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:
-
SSH Key Management: Generating, adding, and managing SSH keys for each new repository can be confusing, especially for those new to Git.
-
Authentication Issues: Dealing with authentication errors due to misconfigured credentials or expired tokens is frustrating and time-consuming.
-
Repository Initialization: Manually creating a repository on GitHub, then initializing it locally and linking the two can involve multiple steps where errors can occur.
-
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. -
Inconsistent Setup: When working across multiple projects or with a team, ensuring consistent repository structure and initial configuration can be challenging.
-
Token and Credential Handling: Securely managing and using personal access tokens or other credentials across different environments and projects can be risky and complex.
-
Project-Specific Configurations: Setting up project-specific Git configurations (like user email) for each new repository is often overlooked in manual setups.
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.
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.
- 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.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License.
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! 🎉