git add, commit and push commands in one?

前端 未结 30 1501
隐瞒了意图╮
隐瞒了意图╮ 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:59

    Building off the lazygit answer, the following solution adds a user check to verify the changes before pushing. It will revert the commands if cancelled. And all that will happen if and only if there are changes in the local repo.

    ### SAFER LAZY GIT
    function lazygit() {
      git add .
      if git commit -a -m "$1"; then
        read -r -p "Are you sure you want to push these changes? [y/N]} " response
        case "$response" in
          [yY][eE][sS]|[yY])
            git push
            ;;
          *)
            git reset HEAD~1 --soft
            echo "Reverted changes."
            ;;
        esac
      fi
    }
    

提交回复
热议问题