1

Every time I want to update a repository, for which I'm the owner and only contributor, it takes four often very redundant steps:

git add .
git commit -m "filename.html"
git push origin master

followed by entering the username and password.

I already set it such that it remembers the username and password (following steps like these: Git push requires username and password and others), but I still have to log in every first push, and it also times out so that if I don't do it for several minutes, I have to log in again.

And I know that if no new files have been created then I can remove the add line and use git commit -am "filename.html" instead. Still, it would be nice if git could just monitor the whole directory instead of needing to manually add every new file.

Is there any way to automate or eliminate some of this?

Addem
  • 3,635
  • 3
  • 35
  • 58
  • Yea, make a shell script that does all of those things, then call the script. – gman Jan 04 '20 at 15:39
  • Those are not redundant steps... Each one should be deliberate. For instance, you do want to be careful about what you stage. – jub0bs Jan 04 '20 at 15:47
  • @jub0bs I have never needed to be careful and don't foresee the need in the next year. So I'm just always thoughtlessly entering the same thing 20 times a day, it'd be nice to get this out of the way. – Addem Jan 04 '20 at 15:53
  • @Addem That's how sensitive stuff ends up in repositories. Not to mention the terrible commit message. But each to their own, I suppose... – jub0bs Jan 04 '20 at 16:23

2 Answers2

2

I already set it such that it remembers the username and password

Use ssh instead and you will not need to use username/password

# Open Git Bash.
# Run ssh-keygen and follow the on-screen messages (or simply click Enter till it over)

$ ssh-keygen

# Copy the key file (the content of the public key) located in:

~/.ssh/id_rsa.pub

And you can always use a single line command: (or write a script to save time)

git add . && git commit -m "filename.html" && git push origin master
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
1

make a file called gcp

Inside put these lines

#!/bin/sh
set -e
git add .
git commit -m "$1"
git push origin master

or on Windows call it gcp.bat

and put these lines

git add .
git commit -m "%1" || exit /b %errorlevel%
git push origin master

now put gcp in your path and type

gcp "commit msg"

to run the commands.

ps: Personally I wouldn't do this but here's some rope.

gman
  • 100,619
  • 31
  • 269
  • 393