Makefile git add commit push github All in One command

Part A: (introduction)

As a remember, the traditional way of adding a file to a repository using the command line is summarized into 3 steps as follow:

Step 1:

  1. Open the terminal.
$ git add .

Step 2:

Commit the file that you’ve staged in your local repository.

$ git commit -m "Add existing file"

Step 3:

Push the changes in your local repository to GitHub.

$ git push origin branch-name

Part B: (solution)

How to run ALL in one command from within a Makefile?

Put all git add, git commit, git push command in a makefile, In just 3 simple steps as follow:

Step 1:

You need just to make a “makefile” in your project directory. Attention: makefile does not have any extension. Just “makefile” that’s it.

In Linux or Mac you can create a makefile using:

touch makefile
You see makefile among the others files

Step 2:

put these commands in that makefile:

Check this github link to get access to the script.

git:
git add .
git commit -m "$m"
git push -u origin master

Attention: Each line after the first line, I mean (git :) , is starting with a tab and not space. Something Like this:

note -1 :

As already Github suggested to rename master branch to main we can use main instead of master at the end of the last line, Just in the case you are working with main put this:

git push -u origin main

note -2 :

For putting a long message with a title and body refer to Step 4.

Step 3:

In terminal do this:

make git m="your message"

and you will see such message in terminal:

That’s it!

https://github.com/HPWebdeveloper/Git-One-Command

Step 4: (Optional)

Sometimes the git message has a long body and you want to divide it into multiple lines.

In such scenario the best practice is to write a short message as the title and the rest long part of the message as the body when you do the git commit.

How to do this with one git command?

Instead of what you put in the makefile in step 3 put this new one:

https://github.com/HPWebdeveloper/Git-One-Command/blob/main/makefile-With-Title-And-Body

As you see above I used -m twice! The first one assumed as the title $tand the second one assumed as the body $b.

How to use? Just after create the makefile in the root of your project, in the terminal run this:

make git t="title" b="long body"

As an example when you run the command you will see:

and then do:

git log

you see:

And also the message/comment in Github appears like so:

As you see the first comment is shown as the main commit message (title) and the second one is shown as the description/body (with smaller font).

Note:

make git t="message" b=""
or
make git t="message"

Will leave a blank message for the body part.

Bonus:

I:

Bash file for continuous deployment of static pages: here

II:

Link to this repo for more aliases.

See how I shorten some git commands with some aliases. I put these 4 aliases in the .bashrc or .zshrch file (It is not a makefile!).

alias gc="git checkout"
alias gpo="git push origin"
alias gm="git merge"
alias glog="git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

and then do

source ~/.bashrcorsource ~/.zshrch

Whenever you want to see what each alias does, you can simply run this command in your shell as an example:

alias gc

The result will be:

Posting daily about Python, Laravel, Livewire, Nuclear Physicist PhD

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store