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 Sometimes I'm changing only one letter, CSS padding or something. Still, I have to write all three commands to push the changes. There are many projects where I'm only one pusher, so this command would be awesome!
733 Answers
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.
19I ended up adding an alias to my .gitconfig file:
[alias] cmp = "!f() { git add -A && git commit -m \"$@\" && git push; }; f" Usage: git cmp "Long commit message goes here"
Adds all files, then uses the comment for the commit message and pushes it up to origin.
I think it's a better solution because you have control over what the commit message is.
The alias can be also defined from command line, this adds it to your .gitconfig:
git config --global alias.cmp '!f() { git add -A && git commit -m "$@" && git push; }; f' 8While 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!")
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.
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.
12You can use bash script , set alias to launch any command or group of commands
git commit -am "your message" && git push 3Set as an alias in bash:
$ alias lazygit="git add .; git commit -a -m '...'; git push;"; Call it:
$ lazygit (To make this alias permanent, you'd have to include it in your .bashrc or .bash_profile)
2Simpliest solution would be to:
git commit -a -m "commit" && git push git add is already contained in -a parameter of commit, but if you want you can connect them all:
git add . && git commit -a -m "commit" && git push 0In 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.
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).
If the file is already being tracked then you do not need to run git add, you can simply write git commit -am 'your message'
If you do not want to write a commit message you might consider doing something like
git commit --allow-empty-message -am ''
If you're using a Mac:
Start up Terminal and input
cd ~/to go to your home folderType
touch .bash_profileto create your new file.Edit
.bash_profilewith your favourite editor (or you can just typeopen -e .bash_profileto open it in TextEdit).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" This Result - Try this: Simple script one command for git add, git commit and git push
Open your CMD on Windows and paste this answer
git commit -m "your message" . && git push origin master
I use a batch file:
@ECHO OFF SET /p comment=Comment: git add * git commit -a -m "%comment%" git push 1As 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 2Write 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" .
I like to run the following:
git commit -am "message";git push 1For the macOS users:
Open your Terminal or iTerm2 or another terminal that you use.
Move to your User profile folder with command
~/. It's a default folder for.bash_profilefile:
Type
nano .bash_profileThis command will open the.bash_profiledocument (or create it if it doesn’t already exist) in the easiest to use text editor for terminal –nano.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 } Now save your changes by typing
ctrl + oand hit return to save. Then exitnanoby typingctrl + x.Now we need to activate your changes. Type
source .bash_profile(or. ~/.bash_profile) and watch your prompt change.In iTerm2
Preferences/Profiles/General/Commandset toLogin ShellandSend text at starttosource ~/.bash_profile. So you don't need to make it manually after each macOS restart.
For MAC VSC users the best setup is:
1) press 'shift+cmd+P' and type:
Shell Command: install 'code' command in PATH Press ENTER (this will install code command to get to the bash_profile easily)
2 ) you can now run: code ~/.bash_profile to open the empty bash_profile
3) enter a new function in there:
function lazygit() { git add . git commit -m "$*" git push } 4) now restart VSC
5) make a change, save it and type lazygit message to run the three commands concurrently
There are some issues with the scripts above:
shift "removes" the parameter $1, otherwise, "push" will read it and "misunderstand it".
My tip :
git config --global alias.acpp '!git add -A && branchatu="$(git symbolic-ref HEAD 2>/dev/null)" && branchatu=${branchatu##refs/heads/} && git commit -m "$1" && shift && git pull -u origin $branchatu && git push -u origin $branchatu'
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"
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 } 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:
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"
If you use VSCode, you can download this extension which will let you do it in one simple keyboard shortcut.
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 Since the question doesn't specify which shell, here's the eshell version based on the earlier answers. This goes in the eshell alias file, which might be in ~/.emacs.d/eshell/alias I've added the first part z which let's you quickly cd to a directory, so that this can be run no matter what your current directory is.
alias census z cens; git add .; git commit -m "fast"; git push 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:
This is perfect for command grouping.
{ 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' 1I 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.

