A bash script that automates the process of pushing a project to GitHub.
- 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
- Git installed on your system
- GitHub account
- Personal Access Token with
reposcope
- Go to: https://github.com/settings/tokens
- Click "Generate new token" → "Generate new token (classic)"
- Give it a descriptive name (e.g., "Auto Push Script")
- Select the
reposcope (full control of private repositories) - Click "Generate token"
- Copy the token immediately (you won't be able to see it again!)
-
Make the script executable:
chmod +x push_to_github.sh
-
Navigate to your project directory:
cd /path/to/your/project -
Run the script:
./push_to_github.sh
-
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)
- Initializes git repository (if not already initialized)
- Creates a new repository on GitHub via API
- Creates/updates .gitignore file
- Adds all files to git
- Commits changes
- Configures remote repository
- Pushes code to GitHub
- Updates remote to use SSH for future pushes
$ ./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- Make sure your token has the
reposcope - Verify the token is correct and hasn't expired
- Check that your GitHub username is correct
- The script will continue and try to push to the existing repository
- Make sure you have write access to the repository
- GitHub has a 100MB file size limit
- Remove large files or use Git LFS
- Update .gitignore to exclude large files
- 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
Free to use and modify as needed.