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
The Code
#!/bin/bash
git add .
git commit -m "$1"
git push
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)
The entire file should be like this:
Now we need to give execute permission to the file.
Follow the command.
chmod 700 gitpush.sh
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:
The 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 ~
Open your shell script; I'm using zsh.
vim .zshrc
If you are using bash, it must be .bashrc
. You can check that by
echo $SHELL
The core command
alias -g gitpush='/home/scor32k/blogs/scripts/gitpush.sh $1'
restart the shell (close the terminal and open again). This will globally set the alias.
Now the fun
Follow
I have only used
git push "commit message"
and all three imp git commands are done.
This was just a fun project. I thought of creating
Top comments (2)
Automating things with scripts always feels nice. But in this case I am personally a bit opposed to it due to
In the long run, especially in larger, company-wide, projects it's important to write good commit messages. You can read my longer explanation here: Don't use 'git commit -m'.
And as a side-note,
git add .
only adds the files from the current directory and down. If you are not in the project root you may miss some files. If you truly want all changed files you should usegit add -A
Hey Casper,
Your all the points are valid.
I also follow the method you suggested, but for personal use the script is cool.
This was just a fun project.
Your blogs are awesome Casper. Love it