Hi Everyone,
Hope everyone is doing DIY projects.
I recently started with using git commands for pushing changes to GitHub repository.
While using git commands from terminal, I was facing few errors which I had to simplify. After resolving those, entering same commands again and again becomes bit annoying.
So, to simplify this, I have created a bash script that asks for the user input for their GitHub username, repository name, the file for commit, and the comments for the commit. After this, it commits the changes made.
In the bash script, you need to enter the personal authentication token generated from GitHub, you can see on how to do it here.
How to do it?Pre-requisites: You have to configure your GitHub username and email before hand.
Now I will be explaining the steps to create and execute the bash script, and what further can you modify it according to your experience and use case.
Step 1: Open terminal and clone your working repository with command:
git clone <Repository link>
Step 2: Go to the directory of cloned repository. And then create the bash script as follows:
cd <Path to cloned Repository>
sudo nano bashscriptforgit.sh
Now enter the following commands:
#!/bin/bash
read -p "Enter your github username: " username
read -p "Enter the name of repo you want to push: " repo
read -p "Enter the file name to commit: " filename
read -p "Enter the comment: " comments
git add $filename
git commit -m "$comments"
git remote add origin https://github.com/$username/$repo.git
git push https://<Personal Auth token>@github.com/$username/$repo.git
Note: Make sure you create this bash script inside the cloned repository directory.
After that hit ctrl+x and y and then hit enter.
Explanation of the above script:
First you will asked for few inputs such as your GitHub username, the repository you want to commit, the file name which you made changes and want to push it to GitHub. Then you will be asked for the comment for the commit.
Once these parameters are entered by you, your changed file will be pushed to the repository.
Step 3: Now make the script executable by entering below command:
sudo chmod +x bashscriptforgit.sh
Step 4: Now your script is ready to execute, you can execute it by using below command:
./bashscriptforgit.sh
Feel free to reach out here in comments in case of any issues.
Comments
Please log in or sign up to comment.