DEV Community

Automating git push with just a single bash command

Saurav Jaiswal on May 01, 2020

Say you are working on a project or learning something or doing challenge like #100daysofcode and you are only person who is committing files to th...
Collapse
 
craigewert profile image
CREEE

I am mystified. What was wrong with

git push

?

Collapse
 
sauravjaiswalsj profile image
Saurav Jaiswal • Edited

I did this because I have been doing 100 days of code for quite a long time and repeatedly pushing file with same command was quite irritating for me. So I thought to abstract the whole process into a single bash command. Hence I did all this. I found it the process useful so I thought to share with the community.

Collapse
 
guzzur profile image
Felix Razykov

This one does add all -> commit with message -> push

Collapse
 
craigewert profile image
CREEE

git commit -a -m "message here" & git push

And if you do it once, its always in your history

Thread Thread
 
evankapantais profile image
Evan Kapantais

That's a better approach.

Thread Thread
 
craigewert profile image
CREEE

Actually I dont do that myself. I always leave off the -m and let it pop up vim for me to enter a commit message. Usually I want to review what files are getting committed, and often my commit message is a short story.

Thread Thread
 
evankapantais profile image
Evan Kapantais

Yeah, I see your point. The way I see it, even setting up aliases makes is much easier than having to condense everything in a single line.

Collapse
 
thorstenhirsch profile image
Thorsten Hirsch

Did you really hide my comment? I even told you about a bug in your script that you've fixed now.

Collapse
 
sauravjaiswalsj profile image
Saurav Jaiswal

Yes I did!! It was a typo not a bug

Collapse
 
thorstenhirsch profile image
Thorsten Hirsch

I find this very unkind. My comment was not offending by any means.

Thread Thread
 
sauravjaiswalsj profile image
Saurav Jaiswal

It was aggressive and it did offend me. I think it would be nice of you of you appreciate things instead saying what you prefer.

Thread Thread
 
thorstenhirsch profile image
Thorsten Hirsch

It's not about things I prefer. I started a conversation whether the recommendations you give in your blog are best practice.

Thread Thread
 
sauravjaiswalsj profile image
Saurav Jaiswal

Alright. I might have misread. I will take your suggestions. Thank you for that :)

Collapse
 
sauravjaiswalsj profile image
Saurav Jaiswal

And I believe it would be great if you politely read what I have written on the blog.

Collapse
 
thorstenhirsch profile image
Info Comment hidden by post author - thread only accessible via permalink
Thorsten Hirsch

There are probably not many developers out there who favour the CLI over a Git UI, but at the same time are too lazy to type 3 short commands + commit message instead of 1 short command + commit message.

However my workflow doesn't even include git add . every time I want to commit something. It could add temporary/build files that I don't want being tracked by git, so git -a -m '...' is a safer approach, by which we're down to 2 short commands + commit message (w/o your script).

Oh, and please don't start start a "TLDR" with "Basically this is a self explanatory code", because TLDR makes the reader expect a summary. And telling your reader to read the complete code is the opposite of a summary. Btw: it has to be if [ -n $(...) ] instead of if [ n $(...) ].

Collapse
 
abhishekuniyal profile image
Abhishek Uniyal

Maybe add your password or ssh key in the env too 😝

Collapse
 
darkain profile image
Vincent Milum Jr

shouldn't need to if your ssh-agent is setup properly ;)

Collapse
 
sauravjaiswalsj profile image
Saurav Jaiswal • Edited

Yes! We can. But i avoided it on purpose and thank you for suggesting

Collapse
 
baso53 profile image
Sebastijan Grabar

Everything is #devops nowadays haha.

I can see how this is good to have for your particular use case, but it's exactly that, just for one case. Wouldn't want to accidentaly run this on a local branch other that master though.

Collapse
 
sauravjaiswalsj profile image
Saurav Jaiswal

Yes, it has.But when you are working on something like 100daysofcode or you are only person working on a repository and you know in and out of it. Then, this could be useful instead of every time typing same git commands to push files.

Collapse
 
sauravjaiswalsj profile image
Saurav Jaiswal

I did this because I have been doing 100 days of code for quite a long time and repeatedly pushing file with command was quite irritating for me. So I thought to abstract the whole process into a single bash command. Hence I did all this. I found it the process useful so I thought to share with the community.

Collapse
 
gblbjj profile image
gblbjj

Top!

Collapse
 
sauravjaiswalsj profile image
Saurav Jaiswal

Thanks!

Collapse
 
mandalawine profile image
Abdellatif ABAZINE

Great, a dynamic branch, would be a nice to have.

Collapse
 
sauravjaiswalsj profile image
Saurav Jaiswal

Yes, Abdellatif.

Some comments have been hidden by the post's author - find out more