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
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
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"
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.
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.
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
If you're using a Mac:
Start up Terminal Type "cd ~/" to go to your home folder
Type "touch .bash_profile" to create your new file.
Edit .bash_profile with your favorite editor (or you can just type "open -e .bash_profile" to 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"