zoukankan      html  css  js  c++  java
  • Git config with directory scope, containing multiple repositories

    Git config with directory scope, containing multiple repositories

    based on https://stackoverflow.com/a/44036640/2377961 i think I found a way how it could work.

    first you create different config files for your "custom-scopes" (e.g. professional, freetime, ect.) and add your desired user-config for each scope

    # ~/all-projects.gitconfig
    [user]
       name = TheOperator
    

    .

    # ~/professional.gitconfig
    [user]
       email = yourname@yourwork.com
    

    .

    # ~/freetime.gitconfig
    [user]
       email = yourname@private-email.com
    

    than you add lines like this in your standard gitconfig:

    # ~/.gitconfig
    [include]
        path = all-projects.gitconfig
    [includeIf "gitdir/i:c:/work/"]
        path = professional.gitconfig
    [includeIf "gitdir/i:c:/freetime/"]
        path = freetime.gitconfig 
    

    The directories after "gitdir/i" should match the parents directory of your project groups. In my example you should store your git-repos for freetime-domains e.g. "c:/freetime/my-freetime.domain/.git"

    Can I specify multiple users for myself in .gitconfig?

    With conditional includes in Git 2.13, it is now possible to have multiple user/email coexist on one machine with little work.

    user.gitconfig has my personal name and email. work-user.gitconfig has my work name and email. Both files are at ~ path.

    So my personal name/email applies by default. For c:/work/ dir, my work name/email is applied. For c:/work/github/ dir, my personal name/email is applied. This works as the last setting gets applied.

    # ~/.gitconfig
    [include]
        path = user.gitconfig
    [includeIf "gitdir/i:c:/work/"]
        path = work-user.gitconfig
    [includeIf "gitdir/i:c:/work/github/"]
        path = user.gitconfig
    

    gitdir is case-sensitive and gitdir/i is case-insensitive.

    "gitdir/i:github/" would apply the conditional include for any directory with github in its path.

    Git 2.13 conditional config on windows

    Your global C:/Users/<user-name>/.gitconfig should have this includeIf:

    [includeIf "gitdir:C:/Users/<user-name>/Documents/webstorm/corporate/"]
        path = .gitconfig-work
    

    with having your work Git repos in C:/Users/<user-name>/Documents/webstorm/corporate and the conditional work configuration should be located at C:/Users/<user-name>/.gitconfig-work.

    That's at least working for me in Window's cmd and Cmder. A git config --show-origin --get user.email should than show you from where a config value is loaded/resolved.

    It also seems like the conditional work configuration is only used when issued from within a Git repository.

    C:Users<user-name>Documentswebstormcorporate
    λ git config --show-origin --get user.email
    file:C:/Users/<user-name>/.gitconfig  foo@oss.com
    
    C:Users<user-name>Documentswebstormcorporatesome-repo
    λ git config --show-origin --get user.email
    file:C:/Users/<user-name>/.gitconfig-work  foo@company.com
    
    C:Users<user-name>Documentswebstormcorporatesome-non-repo-dir
    λ git config --show-origin --get user.email
    file:C:/Users/<user-name>/.gitconfig  foo@oss.com
    
  • 相关阅读:
    Android.mk高级写法
    Android Bitmap和Canvas学习笔记
    cocos2dx 3.x 开发环境搭建
    quick cocos2d-x 2.2.4 window环境调试
    Android应用开发相关下载资源(2014/12/14更新)
    quick-cocos2dx-2.2.4环境搭建
    U盘重装Windows系统
    Visual Studio 32位64位的问题和如何编译32位64位工程的问题
    使用UE4.16开发Oculus需要Oculus软件版本高于1.11
    UE4打包程序没有声音-需要安装UE4PrereqSetup_x64.exe
  • 原文地址:https://www.cnblogs.com/chucklu/p/15214189.html
Copyright © 2011-2022 走看看