git add, commit and push commands in one?

前端 未结 30 1481
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 03:15

Is there any way to use these three commands in one?

git add .
git commit -a -m \"commit\" (do not need commit message either)
git push

Som

30条回答
  •  清歌不尽
    2020-12-02 03:58

    While I agree with Wayne Werner on his doubts, this is technically an option:

    git config alias.acp '! git commit -a -m "commit" && git push'
    

    Which defines an alias that runs commit and push. Use it as git acp. Please be aware that such "shell" aliases are always run from the root of your git repository.

    Another option might be to write a post-commit hook that does the push.

    Oh, by the way, you indeed can pass arguments to shell aliases. If you want to pass a custom commit message, instead use:

    git config alias.acp '! acp() { git commit -a -m "$1" && git push ; } ; acp'
    

    (Of course, now, you will need to give a commit message: git acp "My message goes here!")

提交回复
热议问题