LoginSignup
10
12

More than 5 years have passed since last update.

作業中のブランチとは別のリモートブランチにとりあえず作業状態を保存しておく。

Posted at

前置き

こんな機会、よくありますよね

  • 帰宅時間になったので作業状態を保存しておきたい。
  • ロングスパンの作業をやってる雰囲気を演出するために、途中経過をリモートブランチにpushしておきたい。
  • でも、本命のブランチは綺麗にしておいて、けちな修正はgit rebase -iでまとめてからコミットやレビューにだしたい。

それを叶えます。

実際

まずは通常の作業をする。

cd repo
git checkout foo
vi foo/foo.c
git commit -a -m "WIP"
git commit -a -m "WIP"
# ...

帰りたいので、状況をリモートレポジトリにpush。

git commit -a -m "Save WIP" # とりえずコミット
git push origin HEAD:foo-WIP # WIPつけてpushしちゃう

次の日、ブランチはfooのままで作業を再開できる。
また、朝起きてPCが壊れていても、リモートからfoo-WIPをチェックアウトして別の環境で再開できる。

git branch
* foo
vi foo/foo.c

作業が一段落ついたときに、”Fix build error"とか”Revert previous commit”とかを消して、fooにpushできる。

git rebase -i xxxx
git push origin foo # 本命をpush!

あとはレビューなりPull RequestなりでマージすればOK。

蛇足ですが、コードレビューはせいぜい3コミットぐらいにしてから出さないと、読む人が大変なので注意。

10
12
1

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
10
12