git add, commit and push commands in one?

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

    I did this .sh script for command

    #!/bin/sh
    cd LOCALDIRECTORYNAME/  
    git config --global user.email "YOURMAILADDRESS"
    git config --global user.name "YOURUSERNAME"
    git init
    git status
    git add -A && git commit -m "MASSAGEFORCOMMITS"
    git push origin master
    
    0 讨论(0)
  • 2020-12-02 04:15

    This is perfect for command grouping.

    Grouping Commands

    { list; } Placing a list of commands between curly braces causes the list to be executed in the current shell context. No subshell is created. The semicolon (or newline) following list is required.

    legit(){ git add --all; git commit -m "$1"; git push origin master; }
    legit 'your commit message here'
    
    0 讨论(0)
  • 2020-12-02 04:16

    You can try gitu.

    For the first time (node js has to be installed):

    npm install -g git-upload
    

    After that:

    gitu COMMIT_MSG
    

    To issue those three commands at once.

    The good thing is that you don't have to worry when you reinstall your system or when you want to do this on different computers and No file modification is needed. This also work on different platforms (not just Linux and Mac, but also Windows under command prompt like cmd and powershell) just that you have to install npm and nodejs (git of course).

    0 讨论(0)
  • 2020-12-02 04:16

    Write a small script named gitpush.sh with below lines and add it your ~ directory.

    echo $1
    git add .
    git commit -m "$1"
    git push
    

    Now add an alias in ~/.bashrc like below :

    alias gitpush='~/gitpush'
    

    Now from any git repository just write gitpush "message" .

    0 讨论(0)
  • 2020-12-02 04:17

    There are plenty of good solutions already, but here's a solution that I find more elegant for the way I want to work:

    I put a script in my path called "git-put" that contains:

    #!/bin/bash
    git commit "$@" && git push -u
    

    That allows me to run:

    git put -am"my commit message"

    ..to add all files, commit them, and push them.

    (I also added the "-u" because I like to do this anyway, even though it's not related to this issue. It ensures that the upstream branch is always set up for pulling.)

    I like this approach because it also allows to to use "git put" without adding all the files (skip the "-a"), or with any other options I might want to pass to commit. Also, "put" is a short portmanteau of "push" and "commit"

    0 讨论(0)
  • 2020-12-02 04:18

    I like to run the following:

    git commit -am "message";git push
    
    0 讨论(0)
提交回复
热议问题