Question

I was playing around in my terminal and I wrote the following basic function in my .zshrc file:

function gspecial () {
  git merge $1; rspec;
}

With the above when working with separate branches, I can switch to my master branch and call the gspecial with a given branch which will then merge the given branch to master and then immediately after, run the tests.

Calling:

git(master)$ gspecial development

It performs this sequence:

git(master)$ git merge development
git(master)$ rspec

My question is, how would I be able (if possible) to extend this function to cater for the following scenario:

git(development)$ git checkout master
git(master)$ git merge development
git(master)$ rspec

Many thanks!

Was it helpful?

Solution

Listen to the all-wise @devnull or he might swallow you... No, but seriously, he's right:

function gspecial () {
    git checkout $1;
    git merge $2;
    rspec;
}

so then:

$ gspecial master development

will do this:

$ git checkout master
$ git merge development
$ rspec

TIP:

Use a more descriptive name, like git-rspecial for function names.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top