Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 835
Vicky Dev Avatar asked May 06 '17 19:05

Vicky Dev


People also ask

Can you run multiple git commands at once?

All you have to do is to create a file and add all your commands in the same sequence in which you want to execute. That's it!

Can you chain git commands?

Git command chaining is the method of combining several different git commands such that each of them can execute in succession and are separated by the shell operator. && => if the first command successfully executes then it executes the next command else it won't execute next command and it will abort.


1 Answers

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
like image 125
sohan kumawat Avatar answered Sep 20 '22 04:09

sohan kumawat