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
I use a batch file:
@ECHO OFF
SET /p comment=Comment:
git add *
git commit -a -m "%comment%"
git push
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
For 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_profile
file:
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
.
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 + o
and hit return to save. Then exit nano
by typing ctrl + 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/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
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.
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.