295

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!

alex
  • 479,566
  • 201
  • 878
  • 984
Gediminas Šukys
  • 7,101
  • 7
  • 46
  • 59
  • 14
    Have you tried writing a shell script? – Paul Oct 25 '13 at 16:34
  • 1
    http://stackoverflow.com/questions/7852148/function-in-bash-to-commit-and-push-in-one-command – CodeGroover Oct 25 '13 at 16:38
  • There are a lot of changes in my code, when you are changing just a padding in css, or one letter and etc. Commit messages and all these commands stuff adds a lot of work. Not tried a shell script. How it can be done? Thanks! – Gediminas Šukys Oct 25 '13 at 16:38
  • 3
    "(do not need commit message either)" http://images.wikia.com/dragonball/images/a/a7/Facepalm_227785.jpg – Ajedi32 Oct 25 '13 at 20:12
  • 2
    if you are doing a commit for every single instance of a change, you are doing it wrong. do the command's when you're feature is finished or bug is solved (this could be a single change) – Mark Aug 16 '16 at 11:50
  • For anybody stumbling across this question, you should never `git add .` or `git add -a`. This is the source of so much trouble, for so many people. Use `git add -p` or `git add -i`, both of which allow you to examine each change you're adding, and respond with `Y/N` to add or skip that change. This prevents you from adding entire files that shouldn't have been added, or specific changes like `console.log`/`binding.pry`/etc. that you didn't meant to commit. – user229044 Jan 24 '19 at 16:58
  • Yes. Except, `lazygit` is way too much to type! Let's call it `lg`. – Nishant Jul 29 '19 at 08:02

34 Answers34

331

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.

btse
  • 7,811
  • 3
  • 25
  • 30
  • Not working on my ubuntu server, is there something more I should do like a reboot or something? I added your function to the end of my .bashrc script. – Joe Yahchouchi Mar 21 '15 at 15:15
  • 1
    @JoeYahchouchi Not working how? Have you reset your terminal (or resourced the bashrc file)? What happens if you type `which lazygit`? – btse Mar 21 '15 at 19:31
  • Never mind it works, and thank you. A server restart did the trick, I wanted to modify my comment but I could not find it. – Joe Yahchouchi Mar 21 '15 at 21:33
  • 16
    Restart not needed, just do "source .bashrc" – Sambit Tripathy May 14 '15 at 19:09
  • 34
    could use `$*` instead of `$1` to save typing the quotes: `lazygit My commit msg` – Kai Carver Nov 05 '15 at 22:04
  • 23
    @KaiCarver Nice thought, but personally I do not like it. It prevents you from using multiple args, and also goes against the normal convention of a single string arg with spaces being wrapped in quotes. This is second nature to me at this point (and I would assume a lot of developers). Leaving out the quotes feels dirty. – btse Nov 05 '15 at 22:29
  • 8
    lazygit, best name ever! – user1447414 Apr 18 '16 at 11:50
  • @btse I'm pretty sure this git command/workflow also goes against the git conventions/philosophy :P – confused00 Sep 01 '16 at 10:48
  • 1
    Wonderful! works like a charm on mac. I'm getting really lazy :) – marcwjj Oct 15 '16 at 06:27
  • 6
    @btse me being a diplomatic person + it's friday. Here is the function using @KaiCarver suggestion: `function dirtygit() { git add . git commit -a -m "$*" git push }` – OnklMaps Oct 06 '17 at 12:24
  • 2
    @OnklMaps nice, but since stackoverflow comments don’t allow new lines, best put in semicolons: `function dirtygit() { git add . ; git commit -a -m "$*" ; git push }` – Kai Carver Oct 10 '17 at 23:52
  • You can use zsh-autopair to close your quotes, parenthesis etc. – SergioAraujo Jan 17 '18 at 16:23
  • `Making lazygit a function instead of an alias allows you to pass it an argument`: what do you mean exactly? Is it really impossible to pass an argument with an alias? – Basj Jun 23 '18 at 11:20
  • If someone would have told me that in 2007, I would have saved some typing time. – Adam Feb 25 '19 at 00:37
  • Oh, indeed, you can pass arguments to git shell aliases, please see today's update to my answer! – Tilman Vogel Nov 12 '19 at 14:18
  • Using git on Windows 10 here. The lazygit function works for me from the git bash but when I try to run it from command prompt using `git lazygit "Testing alias from cmd"`, it says `lazygit is not a git command`. Any ideas? I usually use the command prompt for most of the terminal work – Abhishek Mar 03 '20 at 08:49
  • Is there a way to have a default commit message, in case user does not provide any argument #1 after `lazygit`? Thanks!! – Matifou Jun 30 '20 at 16:27
  • Pro tip: if like me you're too lazy to type `lazygit`, I recommend to use `glz`. Don't check, it isn't in conflict with the Oh-My-Zsh git plugin. – deb Dec 03 '20 at 14:29
125

I 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'
t0r0X
  • 4,212
  • 1
  • 38
  • 34
madcapacity
  • 1,269
  • 1
  • 8
  • 3
  • 7
    That's exactly what I've been looking for! Works perfectly, thanks! I couldn't find a full syntax reference or a detailed list of commands. What does `!f() { ... }; f`do exactly? More explanation of that line would make the answer even better. – Dmitry Gamolin Mar 21 '18 at 04:05
  • 4
    @DmitriyDemir It defines the function `f`, then calls it. – Oliver Sep 03 '18 at 10:16
  • Works really well. I added `git pull` to the start so that merges are reduced. – Burhan Feb 20 '19 at 10:02
  • 2
    @Oliver Why is it in quotes? Why is there an exclamation point? Does the f at the end call the function? What is "$@"? – Philip Rego Mar 27 '19 at 18:14
  • @PhilipRego Wrong Oliver :p – Oliver Apr 01 '19 at 11:30
  • @Oliver Right Oliver – Philip Rego Apr 02 '19 at 21:13
  • issue in VSCode powershell, i cant add space to commit message :( git cmp "spaces wont work" so i have to add dashes in-between. let me know brightheads if there's some way – GorvGoyl Sep 14 '19 at 07:11
  • @JerryGoyal On Windows, you may need to escape the double quotes around $1 to get it to work from PowerShell (using ... \"$1\" ...) – DReimer May 22 '20 at 20:13
85

While 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!")

Tilman Vogel
  • 9,337
  • 4
  • 33
  • 32
48

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.

Rajender Joshi
  • 4,155
  • 1
  • 23
  • 39
  • 1
    I really like this. ...and have therefore adopted it into my own ~/.bash_profile ;) thanks.. +1 – AO_ Apr 18 '17 at 15:54
  • Careful on the alias `gp`. It would conflict with Oh-My-Zsh's git plugin, where `gp` is used to `git push` – deb Dec 03 '20 at 14:43
43

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.

Wayne Werner
  • 49,299
  • 29
  • 200
  • 290
  • 7
    +1 for the explanation about the workflow. However `git add .` and `git commit -a` [are not the same thing](http://stackoverflow.com/questions/3541647/git-add-vs-git-commit-a) – Gabriele Petronella Oct 25 '13 at 16:46
  • If I'm deleting/creating a file. Does `git commit -a` finds it? For me it fails, but maybe something wrong has been done – Gediminas Šukys Oct 25 '13 at 16:50
  • 9
    Thanks for the explanation, but GIT will not collapse if there will be a command like this for those who knows what they are doing... – Gediminas Šukys Oct 25 '13 at 16:55
  • My bad - I don't use git as much as I would like to - I corrected my answer. Unless you're constantly adding & removing files it seems like `git add .` should still be a fairly rare command (maybe 10-50 times for a reasonably large project?) – Wayne Werner Oct 25 '13 at 21:21
  • 4
    @Lucas: Experienced programmers will tell you that people who ask for an automatic commit-push command don't know what they're doing. There's a reason for the 3-stage code checkin (if you're using feature branches, 4-stage). – slebetman Oct 27 '13 at 01:01
  • @slebetman: there might be some exceptions to this rule where you can't simulate dev env. locally. For eg., we must deploy to real internet server when developing facebook apps. With svn, we have commit to deploy script configured. What's your suggestion for git? – SenG Apr 27 '14 at 12:31
  • @SenG: In git we use push to deploy configured scripts. – slebetman Apr 27 '14 at 23:05
  • 1
    @slebetman: I didn't explain it correctly. With facebook apps, every single change must be deployed to live server even for development. So, we have setup commit hooks to do that. You do a change, commit it and see the change in your app. With git, I need to add, stage then push it to see a single change. Doesn't it look a overkill? – SenG May 10 '14 at 03:17
  • @SenG: Weather or not you consider it overkill does not matter. It's just how it git works. I've developed facebook apps and all my unit test scripts don't need facebook to run. If you need facebook to do testing then you're not doing it right. Of course, you need facebook for integration testing. But you don't need to do integration testing to test your code. Hence my statement stands: experienced programmers will tell you that you don't need to push to test your code. – slebetman May 10 '14 at 06:08
  • 1
    Yes, but you don't need to commit to test your code, either. You should write some code, test it, and *then* commit and push. The legendary use of local git commits to provide some sort of multi-file "undo" functionality is used far more in legend than in reality, in my experience. – Joe Strout May 13 '16 at 18:31
  • @JoeStrout I personally use it far more when I'm prototyping (i.e. I'm trying to have an idea what I'm doing) than when actually developing code. – Wayne Werner May 13 '16 at 18:58
  • Although I agree, OP's situation does arrive very often, typically, when pushing the last version of a pull request, and noticing right after an extra blank line. In those scenarios, we should be able to just add / commit / push quickly. – tomasyany Sep 16 '19 at 15:05
40

You can use bash script , set alias to launch any command or group of commands

git commit -am "your message" && git push 
wonea
  • 4,783
  • 17
  • 86
  • 139
vuhung3990
  • 6,353
  • 1
  • 45
  • 44
  • 2
    If you wish to make this an answer, please add more commentary around how it works. Answers which are simply a code dump are generally not well received. See [answer]. – Heretic Monkey Dec 24 '14 at 05:01
  • I think this should be the correct answer. As it answer the question as succinctly as possible. Just type it into terminal and it works! If you doesn't want to add an alias an alternative would be to simply create a textExpander expand and trigger it via a key-combo. – Sentry.co Dec 14 '16 at 15:43
  • Works beautifully. I think this should be the accepted answer. – datsb Jan 02 '22 at 08:40
22

Simpliest 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
michal.jakubeczy
  • 8,221
  • 1
  • 59
  • 63
21

Set 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)

Gavin
  • 3,901
  • 1
  • 12
  • 5
  • You would need it add that alias to .bashrc or .bash_profile to make it permanent – Gavin Mar 22 '14 at 02:46
  • I think this page can help to explain: http://serverfault.com/questions/3743/what-useful-things-can-one-add-to-ones-bashrc – Gavin Mar 27 '14 at 01:13
11

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.

mcvkr
  • 3,209
  • 6
  • 38
  • 63
8

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).

Fries
  • 349
  • 1
  • 5
  • 10
7

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 ''

Peter Foti
  • 5,526
  • 6
  • 34
  • 47
7

If you're using a Mac:

  1. Start up Terminal and input cd ~/ to go to your home folder

  2. Type touch .bash_profile to create your new file.

  3. Edit .bash_profile with your favourite editor (or you can just type open -e .bash_profile to open it in TextEdit).

  4. 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"
Oozeerally
  • 842
  • 12
  • 24
5

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

This example my picture screenshot : https://i.stack.imgur.com/2IZDe.jpg

Anang Hanafi
  • 51
  • 1
  • 2
4

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
wonea
  • 4,783
  • 17
  • 86
  • 139
cristianzamar
  • 361
  • 4
  • 12
4

I like to run the following:

git commit -am "message";git push
etoxin
  • 4,908
  • 3
  • 38
  • 50
  • 2
    I think the `;` should be replaced with `&&` in your command, since the later will execute the `git push` command only if there's no error on the previous command(s). – Tom Jun 28 '19 at 09:50
4

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:

User folder example

  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
}

Nano text editing

  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. iTerm 2 preferences

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

rusakovic
  • 126
  • 6
3

I use a batch file:

@ECHO OFF
SET /p comment=Comment:
git add *
git commit -a -m "%comment%"
git push
Marcio J
  • 673
  • 7
  • 17
  • probs would be easier if you accepted in args from the command line. i simply go "lezygit MESSAGE" etc. its pretty cool! – John Hon Apr 20 '17 at 03:58
3

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" .

Vaneet Kataria
  • 575
  • 5
  • 14
2

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

AGrush
  • 1,107
  • 13
  • 32
2

Please see my answer,I added everything into a single line

alias gitcomm="echo 'Please enter commit message';read MSG ;git add --all;git commit -am=$MSG;git push"
Alvin567
  • 305
  • 2
  • 8
1

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'

Pierre.Vriens
  • 2,117
  • 75
  • 29
  • 42
Rubens
  • 91
  • 3
1

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"

rvdh
  • 11
  • 2
1

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
}
Matthew Cordaro
  • 677
  • 1
  • 7
  • 26
1

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

Abushawish
  • 1,466
  • 3
  • 20
  • 35
1

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"

skiggety
  • 205
  • 2
  • 7
1

If you use VSCode, you can download this extension which will let you do it in one simple keyboard shortcut.

Alfred
  • 450
  • 4
  • 10
0

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
acs
  • 796
  • 2
  • 14
  • 33
0

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 https://github.com/rupa/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
0

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

Carrot Cake
  • 57
  • 2
  • 8
0

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'
Peter Girnus
  • 2,673
  • 1
  • 19
  • 24
0

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.

james-see
  • 12,210
  • 6
  • 40
  • 47
0

define function in .bashrc

function gitall() {
    file=${1:-.}
    comment=${2:-update}
    echo $file
    echo $comment
    git add $file && git commit -m '$comment' && git push origin master
}

in your terminal

gitall

default gitall will add all in current git repo

gitall some-file-to-add 'update file'

will add certain file to change, and use custom commit message

xyj
  • 1
  • 1
0

I created a dedicated bash script for automating these all, as it gives me a lot of trouble every time.

It looks like this

#!/bin/sh
# Shell Script to add all files, commit them with a commit message from user and then push them to remote GitHub repo
echo "*** Automating Git Add, Commit and Push ***"

#Ask for Username
echo "Enter your GitHub username: "
read username

#Ask for User Github's personal access token
echo "Enter your GitHub personal access token: "
read token

# Ask for repository name
echo "Enter repository name"
read repoName
# Check if repository exists at GitHub
curl "https://api.github.com/repos/${username}/${repoName}.git"
# If repository exits then

if [ $? -eq 0 ]; then
    cd $repoName
    # Display unstaged files
    git status
    git remote set-url origin https://${token}@github.com/${username}/${repoName}.git
    # If there are any uncommited and unstatged files, ask user to commit them
    if [ "$(git status --porcelain)" ]; then
        echo "There are uncommited and unstatged files. Commit them before pushing"
        echo "Enter commit message"
        read commitMessage
        git add .
        git commit -m "$commitMessage"
        git push
        echo "Files pushed to GitHub"
        # else push all commited and staged files to remote repo
    else
        git push
        echo "Files pushed to GitHub"
        
    fi
    #Echo message if there is no files to commit, stage or push
    if [ "$(git status --porcelain)" ]; then
        echo "There are no files to commit, stage or push"
    fi
else
    echo "Repository does not exist"
fi


# End of script

You can simply use it by making a script.sh (or whatever you want to name in) BASH Script, it uses GitHub's Personal Acces Token to authenticate, if you don't have one already, you can find how to get on using this official Documentation.

I hope it solves your problem.

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Feb 21 '22 at 09:27
0

Hello you have just to add un alias with [nano or vi] ~/.bashrc

echo Enter You commit message && read msg && git add . && git commit -m "$msg" && git push origin main 
Aleatoir 3
  • 11
  • 1
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 16 '22 at 19:39