0

I have written a bash script where I can run those same 3-4 git commands to add, commit and push a particular change to GitHub with just one command. This will ask for a commit message and will commit the change with that particular commit message. And finally will push the code.

#!/bin/bash  

echo "Enter the commit message: "  
read msg
git add .
git commit -m "$msg"
git push origin master

Now the problem is that I haven't set up my ssh keys but have a personal access token for authentication. So whenever I run this script, it has to ask for my username and password(PAT) and I have to fill that manually again and again.
Is there any way I can secretly store my username and password somewhere inside the repo and then it automatically reads them and enters them in the terminal whenever it asks for them??

SNEHEL
  • 1
  • Note that bash itself literally *can't* supply the token to Git here, because Git makes sure to reach out to the *user*, not the script. But you can configure a Git *credential helper* to avoid this step. You should however treat the PAT as if it were a password, because it really *is* a password, just a specialized one. – torek Apr 19 '22 at 21:14
  • 1
    "*I haven't set up my ssh keys*" I would suggest [setting up your ssh keys](https://docs.github.com/en/authentication/connecting-to-github-with-ssh) and using an ssh-agent. It's simpler and much more secure. Also, I know it seems inconvenient, but commit + push are separate steps for good reason. One is "I have completed a unit of work" the other is "I am ready to inflict my work on others". – Schwern Apr 19 '22 at 23:51

0 Answers0