you may need this - bash script

Abhishek Pathak - Sep 12 '23 - - Dev Community

I created a bash script for handling

git add., git commit -m "" and git push

Don't ask why,
Yes, I will tell
For a developer, these 3 commands are the most important to work on on a daily basis.

But it's a little bit time-consuming—not much, but 2 seconds, I can say.

So I created this script.
Follow me.

Create a file

vim gitpush.sh
Enter fullscreen mode Exit fullscreen mode

The Code

#!/bin/bash
git add .
git commit -m "$1"
git push
Enter fullscreen mode Exit fullscreen mode

Each line explanation:

#! -> bash shebang

git add . -> add all the files to staging

git commit -m "" -> write changes permanently.

git push -> push to the remote origin.

Exit the vim

a. Enter `Esc`

b. Enter `:`

c: Enter `wq`

![exit vim](https://imgur.com/XA9IOdC.png)
Enter fullscreen mode Exit fullscreen mode

The entire file should be like this:

entire process

Now we need to give execute permission to the file.
Follow the command.

chmod 700 gitpush.sh
Enter fullscreen mode Exit fullscreen mode

Command breakdown
chmod: This is used to change the file permissions.
700: 700 is divided into 3 groups: a) 7, b) 0, and c) 0.

a) refers to the current user.
b) refers to the group
c) refers to other users in the system.

Group a is 7, which means the current user has all the permissions. You can understand this by

[
4: for read,
2 for write,
1 for execute
]

So, 7 = 4 + 2 + 1, so the current user will have all the permissions.

0 means no permissions.

The entire steps will look like:

entire step

The gameplay:

gameplay

As you can see, I have used the absolute path of the file with just the commit message. Liek simple.

But,
In bash, we can use alias to avoid typing the file path every time.

Follow me:

Go to the Home directory

cd ~
Enter fullscreen mode Exit fullscreen mode

Open your shell script; I'm using zsh.

vim .zshrc
Enter fullscreen mode Exit fullscreen mode

If you are using bash, it must be .bashrc. You can check that by

echo $SHELL
Enter fullscreen mode Exit fullscreen mode

The core command

alias -g gitpush='/home/scor32k/blogs/scripts/gitpush.sh $1'
Enter fullscreen mode Exit fullscreen mode

restart the shell (close the terminal and open again). This will globally set the alias.

Now the fun
Follow

final

I have only used

git push "commit message"
Enter fullscreen mode Exit fullscreen mode

and all three imp git commands are done.

This was just a fun project. I thought of creating

. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Terabox Video Player