Is it possible to have different Git configuration for different projects?

前端 未结 12 769
萌比男神i
萌比男神i 2020-12-02 03:44

.gitconfig is usually stored in the user.home directory.

I use a different identity to work on projects for Company A and something else fo

12条回答
  •  盖世英雄少女心
    2020-12-02 04:14

    I'm in the same boat. I wrote a little bash script to manage them. https://github.com/thejeffreystone/setgit

    #!/bin/bash
    
    # setgit
    #
    # Script to manage multiple global gitconfigs
    # 
    # To save your current .gitconfig to .gitconfig-this just run:
    # setgit -s this
    #
    # To load .gitconfig-this to .gitconfig it run:
    # setgit -f this
    # 
    # 
    # 
    # Author: Jeffrey Stone 
    
    usage(){
      echo "$(basename $0) [-h] [-f name]" 
      echo ""
      echo "where:"
      echo " -h  Show Help Text"
      echo " -f  Load the .gitconfig file based on option passed"
      echo ""
      exit 1  
    }
    
    if [ $# -lt 1 ]
    then
      usage
      exit
    fi
    
    while getopts ':hf:' option; do
      case "$option" in
          h) usage
             exit
             ;;
          f) echo "Loading .gitconfig from .gitconfig-$OPTARG"
             cat ~/.gitconfig-$OPTARG > ~/.gitconfig
             ;;
          *) printf "illegal option: '%s'\n" "$OPTARG" >&2
             echo "$usage" >&2
             exit 1
             ;;
        esac
    done
    

提交回复
热议问题