This script automatically commits changes to a specified Git repository when your PC starts, helping to increase your contributions and maintain your daily streak.
Follow the steps below to set up and use the script.
- Download and install Git Bash.
- Create a new repository on GitHub.
- Make the repository private.
- Add a
README.mdfile during the repository creation.
-
Empty the
README.mdfile manually. -
Clone the repository to your local machine in C: Drive (To gain permissions) using the command:
git clone <link_of_git_repo>
-
Open the command prompt (
cmd) inside the cloned repository directory. -
Run the following commands to set up the repository:
git add . git commit -m "Initial setup" git push -u origin main
-
Download the provided script and save it to your local machine.
-
Copy the path of the cloned repository.
-
Open the script in a text editor and update the path in the script for example:
cd C:\Users\abhis\OneDrive\Desktop\DSA_Java
- Press
Win+Rto open the Run dialog. - Type
shell:common startupand press Enter. This will open the Startup folder. - Copy the script into the Startup folder.
The script performs the following tasks:
- Changes the directory to the specified repository location.
- Checks for an active internet connection.
- Gets the current date and time.
- Writes the current date and time to
README.md. - Stages the changes.
- Commits the changes with a predefined message.
- Pushes the changes to the remote repository.
@echo off
:: Change Directory
cd C:\Users\abhis\OneDrive\Desktop\DSA_Java
:check_internet
ping -n 1 8.8.8.8 | find "TTL=" >nul
if errorlevel 1 (
echo Internet connection not available. Checking again in 10 seconds...
timeout /t 10
goto check_internet
)
:: Get the current date and time
for /f "tokens=1-5 delims=/: " %%a in ('echo %date% %time%') do (
set current_date=%%c-%%a-%%b
set current_time=%%d%%e
)
:: Combine date and time
set datetime=%current_date%_%current_time%
:: Write the current date and time to README.md
echo %datetime% > README.md
:: Stage the changes
git add .
:: Commit the changes with a message
git commit -m "Automated commit on %datetime%"
:: Push the changes to the remote repository
git pushBy following these steps, the script will run automatically each time your PC starts, committing and pushing any changes made to the README.md file.
Abhishek Rajput