Git
サーバに共有リポジトリを作る
$ mkdir hoge
$ cd hoge
$ git init --bare
リモートリポジトリ追加
$ git remote add origin ssh://example.com/home/kambara/git-repos/hoge
リモートリポジトリ確認
$ git config remote.origin.url
リモートリポジトリ変更
$ git config remote.origin.url ../foobar
Webアプリだとさらにサーバ側でgit cloneしておく
$ git clone ~/git-repos/hoge
空ディレクトリを追加するには.gitignoreを追加しておく
$ mkdir hoge
$ cd hoge
$ touch .gitignore
削除したファイルの復活。svnのようにupdateではできない。
$ git checkout <masterとかブランチ名> ファイル名
リモートのブランチに切り替える
$ git checkout -b hoge origin/hoge
はまった
git pull しようとするとbranchを指定しろ、と言われる。
$ git pull
You asked me to pull without telling me which branch you
want to merge with, and 'branch.master.merge' in
your configuration file does not tell me, either. Please
specify which branch you want to use on the command line and
try again (e.g. 'git pull <repository> <refspec>').
See git-pull(1) for details.
If you often merge with the same branch, you may want to
use something like the following in your configuration file:
[branch "master"]
remote = <nickname>
merge = <remote-ref>
[remote "<nickname>"]
url = <url>
fetch = <refspec>
See git-config(1) for details.
ちなみに
$ git pull origin master
はできる。
.git/configを見ると、[remote "origin"]は指定されているが、[branch "master"]は指定されていない。
.git/configに以下を追記すると良い。
[branch "master"]
remote = origin
merge = refs/heads/master
直接.git/configを編集してもよいが、コマンドラインでやるなら以下のようにする。
$ git config branch.master.remote origin
$ git config branch.master.merge refs/heads/master
これでgit pullできるようになった。
参考: