Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

git でブランチを切ったら自動でブランチに移動して空のコミットをする #70

Open
shikakun opened this issue Sep 12, 2014 · 2 comments

Comments

@shikakun
Copy link
Owner

  • $ git checkout -b {ブランチ名}
    • で、ブランチを作ったうえに作ったブランチに移動できるのは知っていた。
  • $ git commit --allow-empty -m {コミットメッセージ}

というわけで、よーし作業するぞとなったら上の2コマンドを打って pull request を作ってから作業開始してたんだけど、ブランチを切ったら空のコミットも同時にできちゃっていいんじゃないかな?と思えてきた。

というわけで調べて、.bashrc に以下のような function を書いた。

function branch() {
  git checkout -b $1;
  git commit --allow-empty -m "ブランチを作った: $1";
}

これで、$ branch hogemoge って打つだけでブランチを切ってブランチに移動して空のコミットをできるようになった。git push まで含めることもできるのかな?
ちなみに alias には引数を指定できないらしい。

@2get
Copy link

2get commented Sep 12, 2014

write [alias] section in ~/.giconfig

branch-empty-commit = "!sh -c 'git checkout -b $1 && git commit --allow-empty -m \"empty commit\"' -"

use:

git branch-empty-commit branch-name

@shikakun
Copy link
Owner Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants