LoginSignup
25
22

More than 5 years have passed since last update.

リモートブランチに.gitignoreをpushせずに管理する方法

Last updated at Posted at 2017-02-22

リモートブランチに.gitignoreをpushせずに管理する方法

  • gitの管理に含めたくないファイルがある。
  • .gitignoreファイルに除外対象のファイルを設定したが.gitignoreファイルはリモートにpushしたくない。

そんなシチュエーションに便利。(←そもそもの運用方法が悪いという話はここでは置いておく。)

.gitignoreファイルを作成する

プロジェクトのルートにgitのディレクトリがあることを確認し、.gitignoreファイルを作成する

$ ls -a
. .. .git app

$ vi .gitignore
.gitignore
PROJECT_ROOT/app/tmp/logs/
#↓以下に無視したいファイルを続けて記入

無視したいファイルがきちんと無視できているかを確認。

$ git status

On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    .gitignore


gitのexcludeファイルにgitignoreを追加

あとはこの.gitignore自体を無視したい。

$ vi .git/info/exclude
exclude
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~

.gitignore
# ↑.gitignoreを追加

gitのconfigファイルの設定

さらに、

$ vi .git/config
config
[core]
    excludesfile = /path/to/ignore-definition
    #↑この行を追加

無事に無視することができた。

$ git status
On branch master
nothing to commit, working directory clean

参照

終わりに

もっといい方法があればアドバイスください!

25
22
3

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
25
22