LoginSignup
4
5

More than 5 years have passed since last update.

git submoduleを追加してみる

Posted at

submoduleとは何か?

「特定のリポジトリ」の「特定のコミット」をリポジトリ内の特定のディレクトリに紐付ける仕組みです。

この機能を使ってやりたかったこと

.dotfiles
├── .bashrc
├── .alias
├── .function
├──    :
├──    :
└── .local
    ├── .alias
    └── .function
  • dotfile -> githubで管理
  • dotfile/.local -> bitbucket(非公開)で管理

これです。

dotfileをgithubで管理しているのですが、
どうしても非公開にしたい情報を
今までローカルでgitignoreして管理していました。
が、しかし。

色々試行錯誤しながら修正したりするので
version管理ができないと不便!
ということで、今回submoduleを使ってみることにしました。

(全部bitbucketで管理すればいいじゃんっていうツッコミは、なしで)

使い方

じゃん

stepは以下

別リポジトリを作成

submodule用の別リポジトリを用意

$ mkdir .dotfiles.local
$ cd .dotfiles.local
$ git init
$ echo "#local alias" >> alias
$ git add .
$ git commit -m 'first commit'
$ git remote add origin ssh://git@bitbucket.org/_user_name_/.dotfiles.local.git

submoduleを登録

submoduleを使いたいプロジェクトに移動して、
以下コマンドでsubmoduleを登録。

$ git submodule add git@bitbucket.org:_user_name_/.dotfiles.local.git .local
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   .gitmodules

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

    .locals/

こんな感じで追加されます

cat .gitmodules

[submodule ".local"]
    path = .local
    url = git@bitbucket.org:_user_name_/.dotfiles.local.git
git commit -m "add submodule: .local"
[master 641dad0] add submodule: .local
 1 file changed, 3 insertions(+)
 create mode 100644 .gitmodules

これで追加されている。

thanks

http://vdeep.net/git-submodule
http://qiita.com/go_astrayer/items/8667140aef8875742a36
http://qiita.com/knsh14/items/941f2ec2ec76ef1d1940

4
5
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
4
5