Is it possible to configure user.name and user.email per wildcard domains in .gitconfig?

前端 未结 5 459
不思量自难忘°
不思量自难忘° 2021-01-31 03:00

I have a work computer, and it\'s configured globally to use my work email and name when committing. This is good. However, I\'d like to make some sort of rule that says, \"if t

5条回答
  •  逝去的感伤
    2021-01-31 03:33

    Similar to Mike's answer, but thanks to the uniq command at the fourth line, it will not result in a fork bomb, even if you start a shell inside a shell.

    #!/usr/bin/env bash
    
    # "Real" git is the second one returned by 'which'
    REAL_GIT=$(which -a git | uniq | sed -n 2p)
    
    # Does the remote "origin" point to GitHub?
    if ("$REAL_GIT" remote -v 2>/dev/null |
        grep '^origin\b.*github.com.*(push)$' >/dev/null 2>&1); then
    
        # Yes.  Set username and email that you use on GitHub.
        export GIT_AUTHOR_NAME='*** put your name here ***'
        export GIT_AUTHOR_EMAIL='*** put your email address here ***'
    
    fi
    
    "$REAL_GIT" "$@"
    

提交回复
热议问题