A fully autonomous bash script that prepares your local project and pushes it to a new or existing GitHub repository.
push_to_github.sh
is a fire-and-forget solution for initializing a project on GitHub, handling everything from dependency checks to the final push. It simplifies the repetitive process of setting up a new repository, making it perfect for developers who want to get their code on GitHub quickly and without manual steps.
Feature | Description |
---|---|
Fully Autonomous | Requires zero manual configuration outside of running the script. |
Dependency Checks | Automatically verifies if git and the GitHub CLI (gh) are installed. |
Auto-Installation | If the GitHub CLI (gh) is not found, it attempts to install it using the system's package manager (supports macOS via Homebrew, and Debian/Ubuntu/Fedora/CentOS on Linux). |
Authentication Handling | Checks if you're logged into GitHub and prompts you to log in if you aren't. |
Git Identity Setup | If your local Git user.name and user.email are not configured, it will ask for them and set them for the current repository. |
Smart Repository Handling | Creates a new public repository on your GitHub account if one doesn't exist, or pushes to an existing repository if a repository with the same name is found. |
Effortless Commits | Automatically adds all project files and creates an initial commit. |
User-Friendly | Provides clear, colored output for each step of the process. |
Getting started is as simple as running the script in your project's root directory.
- A terminal or command-line interface.
- A GitHub account.
sudo
or administrative privileges may be required for the one-time installation of the GitHub CLI.
-
Download the Script: Save the script in your project's root directory as
push_to_github.sh
. -
Make it Executable: Open your terminal, navigate to your project directory, and run the following command to give the script execution permissions:
chmod +x push_to_github.sh
-
Run the Script: Execute the script from your project's root directory. Do not use
sudo
../push_to_github.sh
The script will then guide you through the process, asking for your GitHub username, desired repository name, and Git identity if needed.
The script performs the following steps in order:
- Checks for Git and GitHub CLI (gh): Ensures the necessary tools are available.
- Authenticates with GitHub: Uses
gh auth status
to verify your login session. - Collects Repository Info: Prompts you for your GitHub username and the new repository's name.
- Initializes Git: Runs
git init
if the project is not already a Git repository. - Configures Git Identity: Checks
git config
and prompts for your name and email if they are not set. - Commits Files: Stages all files with
git add .
and creates a commit. - Creates & Pushes to GitHub: Uses
gh repo create
to make a new repository and push your code, or updates the remote and pushes if the repository already exists.
Contributions are welcome! If you have ideas for improvements or find a bug, please feel free to open an issue or submit a pull request.
- Fork the repository.
- Create a new branch:
git checkout -b feature/your-feature-name
- Make your changes.
- Commit your changes:
git commit -m "Add some great feature"
- Push to the branch:
git push origin feature/your-feature-name
- Open a pull request.
This project is open source and available under the MIT License.
Made with β€οΈ by developers, for developers