LoginSignup
34
31

More than 5 years have passed since last update.

dotfilsをGitHub管理したいけど.gitconfigには社内proxy情報が…ってときは

Posted at

概要

gitのバージョンが1.7.10以降ならば、.gitconfig内で他のファイルをincludeできます。
ドットファイルを公開リポジトリで管理していても、社内プロキシ情報などだけはinclude先のファイルに記載しておくことで非公開にしておくことが可能です。
includeで指定したファイルがなくてもC1083 error when it can't find a file.なんてエラーはおきませんよ。

はじめに

以下のような記事を書きました。

homeshickとgit submoduleコマンドでプラグインも含めたドットファイルを全て管理する
http://qiita.com/budougumi0617/items/07cd145af12c65dbe77c

でも、うちの会社proxy設定が必要なんです。.gitconfigに認証情報書いているんで公開できません。
でもgitならば解決できます!!!!

.gitconfigincludeして認証情報は公開しない

もう概要でほぼ全て書いてしまったので、具体的なファイルの書き方だけです。

GitHubに公開してもよい.gitconfigファイル

[include]
    path = .gitconfig.local
[user]
    name = budougumi0617
    email = ないしょ@gmail.com
[color]
    ui = auto
[alias]
    br = branch
    co = checkout
    ci = commit
    st = status
    graph = log --graph --date-order -C -M --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --all --date=short
    list = log --pretty=format:\"<%h> %ad [%an] %Cgreen%d%Creset %s\" --date=short
    df = diff
[core]
    autoCRLF = false
[push]
    default = matching

GitHubに公開してはいけない.gitconfig.localファイル

gitconfig.local
[http]
        proxy = http://foo:bar@proxy.example.com:8080
[https]
        proxy = http://foo:bar@proxy.example.com:8080

相対パスなので上記の記載の場合は$HOMEに以下のように設置してあればよいでしょう。

$  ls -a ~/.git*
/Users/budougumi0617/.gitconfig        /Users/budougumi0617/.gitignore_global
/Users/budougumi0617/.gitconfig.local

最後に

gitのバージョンが1.7.10未満だった場合はどんまいです!

34
31
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
34
31