R.A. Epigonos et al.

[git] リモートブランチからローカルブランチを作成

リモート側にあるブランチは master だけではない。いろいろあるリモートブランチに対してコミットしたい場合は、それぞれのリモートブランチに対してローカルブランチを作成しておく。

現在のブランチの状態を確認。

$ git branch -a -vv
  translation_ja                061f94a [origin/master: behind 3] core: fix sentence in ChangeLog
* translation_ja_work           c6c3015 [origin/master: ahead 197] Merge branch 'master' of https://github.com/weechat/weechat into translation_ja_work
  remotes/github/translation_ja d06760c core: update Japanese translations
  remotes/origin/0.0.1          0f3efd7 Fix compilation errors/warnings
  remotes/origin/0.3.1          4c34d00 Version 0.3.1.1
  remotes/origin/0.3.9          2429c9d Version 0.3.9.2
  remotes/origin/1.0            87cc51e core: fix highlight of IRC action messages when option irc.look.nick_mode is set to "action" or "both" (closes #206)
  remotes/origin/arraylist      7f4d9de core: use a sorted arraylist for partial completions
  remotes/origin/branch-0-2-6   d486a02 Version 0.2.6.3
  remotes/origin/master         1a20ef4 core: fix highlight of IRC action messages when option irc.look.nick_mode is set to "action" or "both" (closes #206)
  remotes/origin/travis-tests   e8c03ea core: download debian package libcpputest-dev from weechat.org (Travis CI)

リモートブランチ remotes/origin/1.0 をチェックアウトすると、'detached HEAD' 状態になる。この状態でコミットすることも可能だがコミットの内容を保存したければ、適当なブランチを作成する必要がある。これはコミットの後でも、今でも構わない。ということで、今ブランチを作っておく。

$ git checkout remotes/origin/1.0
Note: checking out 'remotes/origin/1.0'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at 87cc51e... core: fix highlight of IRC action messages when option irc.look.nick_mode is set to "action" or "both" (closes #206)
$ git checkout -b 1.0_translation_ja_work
Switched to a new branch '1.0_translation_ja_work'

このままだと、remotes/origin/1.0 にあった修正を pull する場合に pull 元のリモートブランチを毎回指定することになる。このローカルブランチに対する上流を忘れないうちに設定しておく。

$ git branch --set-upstream 1.0_translation_ja_work origin/1.0
Branch 1.0_translation_ja_work set up to track remote branch 1.0 from origin.

ブランチの状態を確認すると、1.0_translation_ja_work が作成され、pull 元が origin/1.0 になっていることが分かる。

$ git branch -a -vv
* 1.0_translation_ja_work       87cc51e [origin/1.0] core: fix highlight of IRC action messages when option irc.look.nick_mode is set to "action" or "both" (closes #206)
  translation_ja                061f94a [origin/master: behind 3] core: fix sentence in ChangeLog
  translation_ja_work           c6c3015 [origin/master: ahead 197] Merge branch 'master' of https://github.com/weechat/weechat into translation_ja_work
  remotes/github/translation_ja d06760c core: update Japanese translations
  remotes/origin/0.0.1          0f3efd7 Fix compilation errors/warnings
  remotes/origin/0.3.1          4c34d00 Version 0.3.1.1
  remotes/origin/0.3.9          2429c9d Version 0.3.9.2
  remotes/origin/1.0            87cc51e core: fix highlight of IRC action messages when option irc.look.nick_mode is set to "action" or "both" (closes #206)
  remotes/origin/arraylist      7f4d9de core: use a sorted arraylist for partial completions
  remotes/origin/branch-0-2-6   d486a02 Version 0.2.6.3
  remotes/origin/master         1a20ef4 core: fix highlight of IRC action messages when option irc.look.nick_mode is set to "action" or "both" (closes #206)
  remotes/origin/travis-tests   e8c03ea core: download debian package libcpputest-dev from weechat.org (Travis CI)

ソーシャルブックマーク

  1. はてなブックマーク
  2. Google Bookmarks
  3. del.icio.us

ChangeLog

  1. Posted: 2008-10-25T21:46:12+09:00
  2. Modified: 2008-10-25T21:46:12+09:00
  3. Generated: 2023-08-27T23:09:11+09:00