I had a similar problem in that I wanted to make my ~/.gitconfigportable on different platforms so that I could use the same gitconfig on my Macbook and in my Linux VM. I need to be credential.helperdifferent depending on the platform.
generate_gitconfig script bashrc, ~/.gitconfig .
gitconfig script , , , ..
generate_gitconfig script, :
#!/bin/bash
cat <<EOF > $HOME/.gitconfig
[user]
name = Dave Yarwood
email = dave.yarwood@gmail.com
[push]
default = simple
[core]
autocrlf = input
editor = nvim
excludesfile = $HOME/.gitignore_global
[rerere]
enabled = true
EOF
if [[ "$(uname)" == Darwin ]]; then
CREDENTIAL_HELPER="osxkeychain"
elif [[ -n "$(which gnome-keyring-daemon)" ]]; then
CREDENTIAL_HELPER="/usr/share/doc/git/contrib/credential/gnome-keyring/git-credential-gnome-keyring"
fi
if [[ -n "$CREDENTIAL_HELPER" ]]; then
cat <<EOF >> $HOME/.gitconfig
[credential]
helper = $CREDENTIAL_HELPER
EOF
fi