I want to use a bash function in a git alias. So I added this to my .bashrc:
fn() {
echo \"Hello, world!\"
}
export -f fn
Thats because git uses /bin/sh (so your .bashrc is not sourced).
You can call bash in a git alias as specified in this answer.
The thing is the bash shell started by the git command is not loading your .profile (which is the one responsible for including the .bashrc).
There may be other ways to do it but you can work around by doing:
[alias]
fn = !bash -c 'source $HOME/.my_functions && fn'
With the file .my_functions like this:
#!/bin/bash
fn() {
echo "Hello, world!"
}
You can even source .my_functions into your .bashrc if you want the functions to be available from regular shells.