programing

프로젝트별로 Git 구성을 다르게 할 수 있나요?

skycolor 2023. 4. 17. 21:37
반응형

프로젝트별로 Git 구성을 다르게 할 수 있나요?

.gitconfig된다.user.home디렉토리로 이동합니다.

저는 A사 프로젝트와 B사 프로젝트(주로 이름/이메일)에 다른 아이덴티티를 사용하고 있습니다.어떻게 하면 체크인이 이름/이메일에 맞지 않게 두 개의 Git 구성을 가질 수 있을까요?

git 설정에는 프로젝트, 글로벌, 시스템의 3가지 레벨이 있습니다.

  • 프로젝트:프로젝트 구성은 현재 프로젝트에서만 사용할 수 있으며 프로젝트 디렉터리의 .git/config에 저장됩니다.
  • global: 현재 사용자의 모든 프로젝트에서 글로벌 구성을 사용할 수 있으며 ~/.gitconfig에 저장됩니다.
  • system: 모든 사용자/프로젝트에 대해 시스템 구성을 사용할 수 있으며 /etc/gitconfig에 저장됩니다.

프로젝트 고유의 설정을 작성합니다.프로젝트 디렉토리에서 실행해야 합니다.

$ git config user.name "John Doe" 

글로벌 설정을 만듭니다.

$ git config --global user.name "John Doe"

시스템 구성을 만듭니다.

$ git config --system user.name "John Doe" 

짐작하신 바와 같이 프로젝트는 글로벌글로벌 재정의 시스템을 무시합니다.

주의: 프로젝트 구성은 이 특정 레포의 특정 복사/클론 중 하나에 대해서만 로컬이며, 리모트로부터 리클라인된 레포의 경우 다시 적용해야 합니다.커밋/푸시를 사용하여 리모트로 전송되지 않는 로컬파일을 변경합니다.

git 버전 2.13에서 git은 다음을 포함한 조건부 구성을 지원합니다.이 예에서는 A사의 저장소를 복제하고 있습니다.~/company_a및 B에 ~/company_b.

★★★★★★★★★★★★★★★★★★★★★의 마지막에.gitconfig파일에는 다음과 같은 것을 넣을 수 있습니다.

[includeIf "gitdir:~/company_a/"]
  path = .gitconfig-company_a
[includeIf "gitdir:~/company_b/"]
  path = .gitconfig-company_b

「 」의 예.gitconfig-company_a(the)[core]글로벌 ssh 키를 사용할 수 있는 경우 섹션을 생략할 수 있습니다).

[user]
name = John Smith
email = john.smith@companya.net

[core]
sshCommand = ssh -i ~/.ssh/id_rsa_companya

「 」의 예.gitconfig-company_b:

[user]
name = John Smith
email = js@companyb.com

[core]
sshCommand = ssh -i ~/.ssh/id_rsa_companyb

.git/config저장소의 특정 복제본에 있는 파일은 해당 복제본에 대해 로컬입니다.여기에 배치된 설정은 해당 프로젝트의 작업에만 영향을 미칩니다.

로는 (「」)git config.git/config 아니라, 이에요.~/.gitconfig (실행)만--global는자자 경경? ???

감사합니다 @crea1

작은 변종:

https://git-scm.com/docs/git-config#_includes에 기재되어 있는 바와 같이:

이 '하다'로 /,**자동으로 추가됩니다.들어 패턴 " " " " " 입니다.foo/ becomes가 되다foo/** 일치합니다.foo안에 있는 모든 것을 재귀적으로요

나는, ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★.
~/.syslogconfig:

[user] # as default, personal needs
    email = myalias@personal-domain.fr
    name = bcag2
[includeIf "gitdir:~/workspace/"] # job needs, like workspace/* so all included projects
    path = .gitconfig-job

# all others section: core, alias, log…

가 내 안에 ~/wokspace/ 유저 은, 「사용할 수 없다」로 됩니다.
~/.syslogconfig-job:

[user]
name = John Smith
email = js@company.com

하기 , 「」를 사용할 도 있습니다.--local현재 저장소 구성 파일을 사용하려면:

git config --local user.name "John Doe" 

또는 @SherylHohman에서 설명한 바와 같이 다음 명령을 사용하여 로컬파일을 에디터로 엽니다.

git config --local --edit

다른 방법은 dienv를 사용하여 디렉토리별로 설정 파일을 분리하는 것입니다.예를 들어 다음과 같습니다.

.
├── companyA
│  ├── .envrc
│  └── .gitconfig
├── companyB
│  ├── .envrc
│  └── .gitconfig
└── personal
   ├── .envrc
   └── .gitconfig

★★.envrc는음

export GIT_CONFIG_GLOBAL=$(pwd)/.gitconfig

★★★★★★★★★★★★★★★★★..gitconfiggitconfig하다

입니다..gitconfig 삭제:

[user]
    email = my.name@company.com

[include]
    path = ~/.gitconfig

에서는 ★★★만user.email덮어쓰고 은 기본 인 ""에서 .~/.gitconfig.

제 이메일은 다음과 같이 하고 있습니다.

git config --global alias.hobbyprofile 'config user.email "me@example.com"'

새로운때.git hobbyprofile이-이-이-이-이-이-이-이-이-이-이-이-이-이-이-이-이-이-이-이-이

환경 변수를 지정할 수도 있습니다.GIT_CONFIGgit config사용해야 합니다.★★★★★★★★★★★★★★★★ GIT_CONFIG=~/.gitconfig-A git config key value지정된 파일이 조작됩니다.

구성 저장소별 구성 파일)을할 수 ./path/to/repo/.git/config) BTW, 디폴트로 이 파일에 씁니다.

cd /path/to/repo
git config user.name 'John Doe'  # sets user.name locally for the repo

로로 ( ((((((((((((((((((((((((((((((((((((((((:~/.gitconfig.d/그런 다음 저장소 구성 파일에 포함합니다.

cd /path/to/repo
git config include.path '~/.gitconfig.d/myproject.conf'

이 방법은 단일 프로젝트에 속하는 여러 리포지토리에서 동일한 옵션 세트를 사용해야 하는 경우에 적합합니다.셸 에일리어스나 커스텀 Git 명령어를 설정하여 프로파일을 조작할 수도 있습니다.

다음의 순서에 따릅니다.

  1. 시스템에서 .gitconfig를 찾습니다.

    Windows 파일 위치: "C:\Users${USER_NAME.gitconfig" 를 선택합니다.

    Linux 파일 위치: "/usr/local/git/etc/gitconfig"

  2. .gitconfig 파일을 열고 조건에 따라 아래 행을 추가합니다.

     [includeIf "gitdir:D:\ORG-A-PROJECTS\"]
    
     [user]
    
         name = John Smith
    
         email = js@organizationx.com [includeIf "gitdir:~/organization_b/"]
    
     [user]
    
         name = John Doe
    
         email = jd@organizationy.com
    

Github 구성을 사용하여 여러 SSH 키 추가

2021년 8월 13일 이후 git은 HTTP 인증 방식을 지원하지 않기 때문에 이 답변은 업데이트가 필요하다고 생각합니다.

다음의 순서에 따릅니다.

  • 「Git」에되어 있는 키및 )를 합니다.~/.ssh/.
  • 새 SSH 키 생성:
ssh-keygen -t rsa -b 4096 -C "account1@gmail.com"
ssh-keygen -t rsa -b 4096 -C "account2@gmail.com"

, 디폴트 「」를 지정합니다.~/.ssh/id_rsa 및 account1의 ~/.ssh/id_rsa_acc2카에에에2 대대에

  • ssh-agent를 시작하고 account1 및 account2의 개인 키를 추가합니다.
eval `ssh-agent`
ssh-add -k ~/.ssh/id_rsa
ssh-add -k ~/.ssh/id_rsa_acc2

는 명령어로 됩니다.confirm 키는 confirm confirm 입니다.ssh-add -l

  • 및명령어: account1 "account2 " 2ithithithithithith2 " " github " 。★★★★★★★★★★★★★★★★★★:cat ~/.ssh/id_rsa.pub | pbcopy(복사 여부를 확인하려면:pbpaste

  • account1의 사용자 이름과 사용자 이메일을 글로벌 GitHub 구성으로 설정합니다.

git config --global user.name "acc1_username"
git config --global user.email "account1@gmail.com"
  • 만들다~/.ssh/config다음 구성의 파일:
# account1 github
Host github.com
HostName github.com
User git
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa

# account2 github
Host github.com-acc2
HostName github.com
User git
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa_acc2
  • 프로젝트 루트 디렉토리의 프로젝트레벨에서 프로젝트 세트의 사용자 이름과 이메일의 GitHub 계정2 를 설정하려면 , 다음의 순서에 따릅니다.
git config user.name "acc2_username"
git config user.email "account2@gmail.com"
  • 이제 GitHub repo의 SSH 링크를 사용하여 오리진을 복제하거나 추가합니다.
# for account1 repo
git remote set-url origin git@github.com:acc1_username/reponame.git

# for account2 repo
git clone git@github.com-acc2:acc2_username/reponame.git

의심스러우면 언제든지 코멘트를 추가해 주세요.

SSH 키 생성과 긴 명령어 입력의 모든 프로세스에 걸쳐 매우 유용한 셸 스크립트를 발견했습니다.

주의: 이것은 다음 경우에만 해당됩니다.ZSh 정의

https://github.com/tw-yshuang/Git_SSH-Account_Switch

나는 같은 처지에 있다.나는 그들을 관리하기 위해 작은 bash 대본을 썼다.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 <thejeffreystone@gmail.com>

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

가 려 i i고 i i i i i i i i i i i i i i i i i i 。git stash아, 아, 아, 아, 아, 아, 아, 네.는 「, 「Run git」라고 말해 git config --global user.email "you@example.com ★★★★★★★★★★★★★★★★★」git config --global user.name "Your name"계정의 기본 아이덴티티를 설정합니다.그러나 현재 저장소에서만 ID를 설정하려면 --global을 생략해야 합니다.

언급URL : https://stackoverflow.com/questions/8801729/is-it-possible-to-have-different-git-configuration-for-different-projects

반응형