概要
リポジトリ
Gitの公開リポジトリは通常、管理ファイルのみをもつ"bareリポジトリ"として作成される。通常bareリポジトリでは作業ツリーの変更やコミットといった作業は行わず、ファイルのやり取りのみに使用する。また、慣例としてbareリポジトリとして使用するディレクトリには".git"という拡張子が付けられる。
初期設定(git config)
Gitの設定スコープは以下の3つ。
スコープ |
ファイル |
説明 |
system |
/etc/gitconfig |
git configコマンドで--systemオプションを利用する。 |
global |
${HOME}/.gitconfig |
git configコマンドで--globalオプションを利用する。 |
repository |
.git/config |
git configコマンドでオプションは利用しない。 |
一般的な設定例は以下の通り。
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
$ git config --global core.editor vim
$ git config --global merge.tool vimdiff
$ git config --global push.default matching
なお確認方法は以下の通り。
$ git config --list
共有リポジトリの作成(git init)
$ mkdir REPOS_NAME.git
$ cd REPOS_NAME.git
$ git init --bare --shared=true
クローン作成(git clone)
基本的な使い方は以下の通り。
$ git clone ssh://USER@IP/home/USER/PATH/REPOS_NAME.git
ミラーリポジトリ1
親のbareリポジトリから子のbareリポジトリを作成した場合、親リポジトリの変更を子リポジトリからfetchできない。
その場合、子リポジトリをmirrorリポジトリとして作成すればよい。cloneの方法は以下の通り。
$ git clone --mirror ssh://USER@IP/home/USER/PATH/REPOS_NAME.git
リポジトリ内の.configは以下の通り。
[core]
repositoryformatversion = 0
filemode = false
bare = true
symlinks = false
ignorecase = true
hideDotFiles = dotGitOnly
[remote "origin"]
fetch = +refs/*:refs/*
mirror = true
url = ssh://ひみつ
puttykeyfile = ひみつ
ミラーリポジトリ2
やること |
コマンド |
mirror作成 |
git clone -mirror |
bareリポジトリのfetch |
git fetch --all |
bareリポジトリへのpush |
git push --mirror |
ミラーリポジトリ3(別のやり方)
mirrorは実際これと同じ事をしてる??
$ git clone --bare {uri}
$ cd {dir}
$ git config remote.origin.fetch '+refs/*:refs/*'
$ git config remote.origin.url $uri
$ git config remote.origin.mirror true
ローカルリポジトリにマージ(git pull)
基本的な使い方は以下の通り。
$ git pull ssh://USER@IP/home/USER/PATH/REPOS_NAME.git
git cloneコマンドで作成したリポジトリの場合は、.git/config内の"remote"項目で記録されているのでリポジトリ指定は不要。
$ git pull
ローカルリポジトリの内容を送信(git push)
基本的な使い方は以下の通り。
$ git push ssh://USER@IP/home/USER/PATH/REPOS_NAME.git origin master
指定するのは以下の3つ。
- 送信先リポジトリ
- 送信するブランチ(e.g. origin)
- 送信先ブランチ(e.g. master)
Link
最終更新:2013年05月14日 11:59