I am trying to create an alias to remove all branches merged to my current branch. To do so, I wanted to turn the script in Andrew C.'s answer into a git alias, but because it is a multi line script I run into an error.
Asked
Active
Viewed 132 times
2 Answers
0
I managed to do it by
- Making sure all single quotes in the script are changed to double quotes.
- Starting to type my alias, leaving the single quotes open:
git config --global alias.delete-merged-branches '!for mergedBranch in $(git for-each-ref --format "%(refname:short)" --merged HEAD refs/heads/)
note the lack of single quote at the end - This opens the possibility to introduce more than one line of code. The alias command will finish when the closing single quote is introduced.
Full example:
$ git config --global alias.delete-merged-branches '!for mergedBranch in $(git for-each-ref --format "%(refname:short)" --merged HEAD refs/heads/) # leave single quote open
$ > do
$ > git branch -d ${mergedBranch}
$ > done' # Notice the closing single quote here
EDIT Has nothing to do with the issue, but the merit of the script goes to https://stackoverflow.com/a/26152574/8699916 this answer.

perepm
- 940
- 9
- 22
0
You also can create a separate script file: your_alias_script.sh
And then reference it from git config:
[alias]
aliasname = bash -c /path/to/your_alias_script.sh

Monsieur Merso
- 1,459
- 1
- 15
- 18