git add, commit and push commands in one?

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

    As mentioned in this answer, you can create a git alias and assign a set of commands for it. In this case, it would be:

    git config --global alias.add-com-push '!git add . && git commit -a -m "commit" && git push'
    

    and use it with

    git add-com-push
    
    0 讨论(0)
  • 2020-12-02 03:51

    When you want svn-like behavior of git commit, use this in your git aliases in your .gitconfig

    commit = "!f() { git commit \"$@\" && git push; };f"

    0 讨论(0)
  • 2020-12-02 03:52

    I found this yolo alias to be amazing to even submit a random comment to the commit while I am being lazy. It works really well out of the box, so I just do git yolo and all my changes are pushed automatically.

    0 讨论(0)
  • 2020-12-02 03:53

    Building off of @Gavin's answer:

    Making lazygit a function instead of an alias allows you to pass it an argument. I have added the following to my .bashrc (or .bash_profile if Mac):

    function lazygit() {
        git add .
        git commit -a -m "$1"
        git push
    }
    

    This allows you to provide a commit message, such as

    lazygit "My commit msg"
    

    You could of course beef this up even more by accepting even more arguments, such as which remote place to push to, or which branch.

    0 讨论(0)
  • 2020-12-02 03:54

    Add in ~/.bash_profile for adding, committing and pushing with one command put:

    function g() { git commit -a -m "$*"; git push; }
    

    Usage:

    g your commit message
    g your commit message 'message'
    

    No quotes are needed although you can't use semicolons or parenthesis in your commit messages (single quotes are allowed). If you want to any of these just simply put double quotes in you message, e.g.:

    g "your commit message; (message)"
    

    To create a comment in your message do:

    g "your commit message:
    > your note"
    

    There's also a function for adding and committing in a similar way:

    function c() { git add --all; git commit -m "$*"; }
    

    Works exactly the same way that g function and has the same constraints. Just put c instead. E.g.

    c your commit message
    

    You can also add an alias for pushing to the remote:

    alias p='git push'
    

    Usage:

    p
    

    That amounts into 2 letters, c and p you use while working with your git repository. Or you can use g instead to do it all with only one letter.

    Full list of aliases and functions: https://gist.github.com/matt360/0c5765d6f0579a5aa74641bc47ae50ac

    0 讨论(0)
  • 2020-12-02 03:55

    If you're using a Mac:

    1. Start up Terminal Type "cd ~/" to go to your home folder

    2. Type "touch .bash_profile" to create your new file.

    3. Edit .bash_profile with your favorite editor (or you can just type "open -e .bash_profile" to open it in TextEdit).

    4. Copy & Paste the below into the file:

    function lazygit() {
        git add .
        git commit -a -m "$1"
        git push
    }
    

    After this, restart your terminal and simply add, commit and push in one easy command, example:

    lazygit "This is my commit message"
    
    0 讨论(0)
提交回复
热议问题