Function in git config alias doesn't accept multi lines

29 views Asked by At

I created the below alias for git, but it doesn't seem to work in multilines, not even in one line, is the below possible somehow?

[alias]
reset-dev = "!f() {
    current_branch=$(git rev-parse --abbrev-ref HEAD);

    echo "Work finished on branch '$current_branch'. Now resetting back to 'develop' and deleting the branch.";

    read -p "Do you want to continue? (Yes/No): " choice
    case "$choice" in 
      [Yy]|[Yy][Ee][Ss]) 
        echo "Continuing...";
        git checkout develop; # Directly switch to 'develop'
        git pull origin develop; # Directly pull from 'develop'
        git branch -d $current_branch;
        echo "Switched to 'develop' and deleted $current_branch.";
        echo "Reset complete.";;
      *) 
        echo "Operation aborted."; exit;;
    esac
}; f"
1

There are 1 answers

0
LeGEC On BEST ANSWER

Another way to add custom subcommands:

if you create a script named git-foo-bar, which is reachable from your $PATH, you may run git foo-bar as if foo-bar was a valid git subcommand.
If your action is not a one liner anymore I would recommend you write it as a separate git-reset-dev script.


To have an alias that spans over several lines: add \ at the end of each line.