git add, commit and push commands in one?

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

    I use a batch file:

    @ECHO OFF
    SET /p comment=Comment:
    git add *
    git commit -a -m "%comment%"
    git push
    
    0 讨论(0)
  • 2020-12-02 04:02

    If you're using fish shell (building off of btse's answer):

    Save this file within '~/.config/fish/functions' as 'quickgit.fish'. Create the directory if it does not exist. '--git-dir=$PWD/.git' Ensures that we run the git commands against the git project where we called the function

    function quickgit # This is the function name and command we call
        git --git-dir=$PWD/.git add . # Stage all unstaged files
        git --git-dir=$PWD/.git commit -a -m $argv # Commit files with the given argument as the commit message
        git --git-dir=$PWD/.git push # Push to remote
    end
    

    Restart terminal, navigate to project, make changes, and now you can call 'quickgit "example message"'. Changes will now be added, committed, and push :).

    Also can be found as a Gist here: https://gist.github.com/Abushawish/3440a6087c212bd67ce1e93f8d283a69

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

    For the macOS users:

    1. Open your Terminal or iTerm2 or another terminal that you use.

    2. Move to your User profile folder with command ~/. It's a default folder for .bash_profile file:

    1. Type nano .bash_profile This command will open the .bash_profile document (or create it if it doesn’t already exist) in the easiest to use text editor for terminal – nano.

    2. Now you can make a simple change to the file. Paste these lines of code to change your Terminal prompt:

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

    1. Now save your changes by typing ctrl + o and hit return to save. Then exit nano by typing ctrl + x.

    2. Now we need to activate your changes. Type source .bash_profile (or . ~/.bash_profile) and watch your prompt change.

    3. In iTerm2 Preferences/Profiles/General/Command set to Login Shell and Send text at start to source ~/.bash_profile. So you don't need to make it manually after each macOS restart.

    Credentials: https://natelandau.com/my-mac-osx-bash_profile

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

    I use this in my .bash_profile

    gitpush() {
        git add .
        git commit -m "$*"
        git push
    }
    alias gp=gitpush
    

    It executes like

    gp A really long commit message
    

    Don't forget to run source ~/.bash_profile after saving the alias.

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

    I think you might misunderstand the workflow that git was designed for. (To clarify/correct what I meant in the comment, you don't need the git add ., since commit -a usually serves the same purpose - adding any changes that have not yet been staged, if the files have already been added)

    Typically you'll do something like this:

    # make some changes
    $ git commit -a -m "Changed something"
    # make some more changes
    $ git commit -a -m "Changed something else"
    

    wash, rinse, repeat, until you've finished feature X, or you're at a stopping point, or you just want other people to see what you've done. Then you do

    $ git push
    

    Git is not SVN - but it appears that you're trying to use it as such. You might find some of the resources at the end of the article here to be of some use.

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

    In Linux/Mac, this much practical option should also work

    git commit -am "IssueNumberIAmWorkingOn --hit Enter key
    > A detail here --Enter
    > Another detail here --Enter
    > Third line here" && git push --last Enter and it will be there
    

    If you are working on a new branch created locally, change the git push piece with git push -u origin branch_name

    If you want to edit your commit message in system editor then

    git commit -a && git push 
    

    will open the editor and once you save the message it will also push it.

    0 讨论(0)
提交回复
热议问题