Multiple git commands in single command executed in order they are encountered by compiler

Vicky Dev picture Vicky Dev · May 6, 2017 · Viewed 9.6k times · Source

I have following list of commands that I run in respective order so that a source project can be committed and pushed to the repository on Bitbucket:

git init
git remote add origin https://[BitBucket Username]@bitbucket.org/[BitBucket Username]/[BitBucket Repository Name].git
git config user.name "[BitBucket Username]"
git config user.email "[BitBucket Email ID]"
## if email doesn't work then use below ##
git config --global user.email \<\>
git add *
git commit -m "[Comment]"
git push -u origin master

Now instead of putting each and every line at their respective time and order, I want to know, if there is a possibility that I can chain all these into single git command and maintain the same order, something like below ?

git init remote add origin https://[BitBucket Username]@bitbucket.org/[BitBucket Username]/[BitBucket Repository Name].git  config user.name "[Username]" ....

Or atleast combine multiple same category params like below ?

git config user.name "[BitBucket Username]" user.email "[BitBucket Email ID]"

I need to know possibility of both scenarios with examples.

Answer

sohan kumawat picture sohan kumawat · Feb 16, 2018

We can use list off command in single command for example:

git add . && git commit -m "updated pom file" && git push

or:

git stash pop && git add . && git commit -m "updated pom file" && git push
  • && -> if 1st command successfully executes then execute next command else it won't execute next command.
  • & - it executes all the command
  • || - execute next command if 1st one failed