Git flow - batch commands

Asked

Viewed 166 times

2

Each time you finish a branch, whether it’s release, Feature or Hotfix, I have to follow a series of commands to publish the changes to my repository. For example: I’ll finish a Hotfix of name ht001 then I do:

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

Obviously you could run everything in one command using &&

This is all because Finish does everything locally When finishing this command runs locally publish my local changes master Merger tag ht001

I would like to give Finish, it already publish also in my repository the changes.

You have with or always will need to run all commands in conjunction with git flow.

OBS. I am not using graphic inteface for control and would not like to use.

1 answer

2


You can create a alias git containing a function bash to do what you need by inserting it into the [alias] of your file .gitconfig:

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

Thus, when executing the alias git pub above, you just need to pass your Hotfix name:

$ git pub ht001

The commands were chained with the use of && to ensure that each of them will only be executed if the previous command successfully terminates.

Since the command itself is executed by the shell, it is a shell script. "Unwound" in several lines, it would be 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 newcomer.

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

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

  • 1

    +1, I use alias but did not know it was possible to pass a "variable" (in this case the name of Hotfix). I was only in doubt the meaning of f()

  • 1

    It’s a shell function statement, to be called straight ahead. So you can manipulate the positional parameters passed pro git using the numeric attribute variables.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.