Git flow - batch commands

2

Every time I've finalized a branch, be it release, feature or hotfix, I have to follow a series of commands to publish changes to my repository. For example: I will end a hotfix named ht001 so I do:

git flow hotfix finish ht001
git checkout develop
git push
git checkout master
git push
git push origin ht001

Obviously I could run everything in one command using & &

That's all because finish does everything locally At the end of this command execute locally post my local changes merge in master merger in develop tag ht001

I would like to give the finish, it already published also in my repository the changes.

It has or will always be necessary to execute all the commands together with git flow.

OBS. I'm not using graphical inteface for control and would not like to use it.

    
asked by anonymous 22.05.2018 / 19:59

1 answer

2
You can create a alias of git containing a bash function that does what you need by inserting it in the [alias] section of your .gitconfig file:

[alias]
        pub = "!f() { git flow hotfix finish \"$1\" && git checkout develop git push && git checkout master && git push && git push origin \"$1\"; }; f"

So when running the alias git pub above, you just need to pass the name of your hotfix:

$ git pub ht001

Commands have been chained using && to ensure that each of them will only be executed if the previous command succeeds.

Since the command itself is executed by the shell, it is a shell script . "Unrolling" in several lines would look like this:

f() { 
    git flow hotfix finish \"$1\" &&
    git checkout develop git push &&
    git checkout master &&
    git push &&
    git push origin \"$1\"; 
}; 
f

That is, we create a function called f , inside it we execute what we need to do, using the positional parameters passed to the alias through the numeric variables $ 1, $ 2 etc, and finally we call the function f newly declared.

So, every time you run git pub x , git declares the f() function and then executes it, passing x as a parameter.

Remember that aliases started at "!" are always executed by the shell from the root directory of your repository, so avoid using relative paths inside the script.

    
23.05.2018 / 04:21