Skip to content

1NF1N172/github-push-script

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

GitHub Auto-Push Script

A bash script that automates the process of pushing a project to GitHub.

Features

  • Automatically initializes git repository if needed
  • Creates GitHub repository via API
  • Handles authentication with Personal Access Token
  • Supports both private and public repositories
  • Creates default .gitignore file if missing
  • Configures remote and pushes code
  • Sets up SSH for future pushes

Prerequisites

  • Git installed on your system
  • GitHub account
  • Personal Access Token with repo scope

Getting a GitHub Personal Access Token

  1. Go to: https://github.com/settings/tokens
  2. Click "Generate new token""Generate new token (classic)"
  3. Give it a descriptive name (e.g., "Auto Push Script")
  4. Select the repo scope (full control of private repositories)
  5. Click "Generate token"
  6. Copy the token immediately (you won't be able to see it again!)

Usage

  1. Make the script executable:

    chmod +x push_to_github.sh
  2. Navigate to your project directory:

    cd /path/to/your/project
  3. Run the script:

    ./push_to_github.sh
  4. Follow the prompts:

    • Enter your GitHub username
    • Enter your GitHub password (optional, can skip)
    • Enter your Personal Access Token (required)
    • Enter repository name
    • Choose if repository should be private (y/n)
    • Enter commit message
    • Enter repository description (optional)

What the Script Does

  1. Initializes git repository (if not already initialized)
  2. Creates a new repository on GitHub via API
  3. Creates/updates .gitignore file
  4. Adds all files to git
  5. Commits changes
  6. Configures remote repository
  7. Pushes code to GitHub
  8. Updates remote to use SSH for future pushes

Example

$ ./push_to_github.sh
==========================================
  GitHub Auto-Push Script
==========================================

[INFO] Initializing git repository...
[SUCCESS] Git repository initialized

Enter your GitHub username: 1NF1N172
Enter your GitHub password (optional, press Enter to skip): 
Enter your GitHub Personal Access Token: ghp_xxxxxxxxxxxxx
Enter repository name (e.g., my-project): my-awesome-project
Should the repository be private? (y/n) [default: y]: y
Enter commit message [default: Initial commit]: Initial commit
Enter repository description (optional, press Enter to skip): My awesome project

[SUCCESS] Repository 'my-awesome-project' created successfully on GitHub!
[SUCCESS] Code successfully pushed to GitHub!

Repository URL: https://github.com/1NF1N172/my-awesome-project

Troubleshooting

Authentication Failed

  • Make sure your token has the repo scope
  • Verify the token is correct and hasn't expired
  • Check that your GitHub username is correct

Repository Already Exists

  • The script will continue and try to push to the existing repository
  • Make sure you have write access to the repository

Large Files Error

  • GitHub has a 100MB file size limit
  • Remove large files or use Git LFS
  • Update .gitignore to exclude large files

Security Notes

  • The script uses HTTPS with token for initial push
  • After successful push, remote is updated to use SSH
  • Never share your Personal Access Token
  • Consider using SSH keys for better security

License

Free to use and modify as needed.

About

Automated script to push projects to GitHub

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages