'How to create an alias composed of many commands?

Commands are:

git checkout master
git remote add upstream [email protected]:minio/console.git
git fetch upstream
git checkout master
git rebase upstream/master

What I want is to type one word and get all of them executed



Solution 1:[1]

You don't have to do anything special. Just put all the commands in the alias.

alias aliasname='git checkout master
git remote add upstream [email protected]:minio/console.git
git fetch upstream
git checkout master
git rebase upstream/master'

Solution 2:[2]

You can define an alias that executes multiple commands, simply by using the ; to separate the comamnds: git checkout master ; git remote ...

But then, consider to simply write a small helper script instead.

Solution 3:[3]

What I would do is:

File: ~/.zshrc <--- Warning: This is not bash, please use .bash_profile accordingly to fit your needs!

Content:

function updateForkedConsoleRepo() {
    git checkout master
    git remote add upstream [email protected]:minio/console.git
    git fetch upstream
    git rebase upstream/master
    echo "git push if all goes well"
}

Now with one word you can execute all your commands:

$ source ~/.zshrc
$ updateForkedConsoleRepo                                  

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Barmar
Solution 2 GhostCat
Solution 3