How to Construct Custom Bash Commands for GIT
Posted By : Ishaan Madan | 30-Nov-2018
Introduction:
In this blog, we will be learning how to create custom shortcut commands (aliases) in bash. The commands can be configured to execute multiple commands by just a single bash command. This comes really handy when one has to repeatedly do some task which involves multiple commands, for instance: creating builds, pushing code to git, etc
For the sake of comprehensibility, in this blog, we will create a custom command to create a local GIT branch from an updated version of the master.
Pre-requisites:
- Operating System - Ubuntu.
- GIT (latest stable version).
- Editor (Nano/VS code/Gedit)
Implementation:
The custom commands are generally placed and defined in '.bashrc'
file, this is basically a hidden file present in the home directory and thus is accessible from any location in the terminal. However, it is not an ideal practice to define all sort of custom usage commands in system files. For that reason. it is recommended to create a custom file ( ~/.custom_aliases) and place all our aliases in it.
Note: It is necessary to load the aliases using source ~/.custom_aliases, else the aliases just won't work.
Step 1:- Creating the custom_aliases file.
# create file
touch ~/.custom_aliases
Step 2:- Open file custom_aliases.
# opens file
gedit ~/.custom_aliases
Step 3:- Enter custom function to execute multiple commands.
# Multiple commands
function createBranchFromMaster() {
git checkout master
git pull origin master
git checkout -b "$1" master
}
Step 4:- Changes update.
# update file
source ~/.custom_aliases
Usage:
# create branch
createBranchFromMaster custom_branch
Conclusion:
For every task performed, time is a vital factor that impacts the performance and efficiency of a programmer. Hence, it is important to be efficient and creating such custom commands helps the cause greatly.
Thanks
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Ishaan Madan
Ishaan, a skilled technical project manager, excels at breaking down complex projects into manageable tasks. With a background in both technology and project management, he offers a unique perspective to every project he undertakes. His effective communication skills enable him to collaborate seamlessly with both technical and non-technical stakeholders, ensuring everyone is aligned towards shared objectives. He has hands-on experience in utilizing agile methodologies like Scrum and Kanban to drive project management and foster team collaboration. He leverages project management tools such as JIRA, Trello, and Clickup to monitor progress, manage tasks, and facilitate communication among team members and stakeholders. Moreover, his proficiency in full-stack development empowers him to comprehend the technical aspects of projects and provide guidance to developers when necessary. He demonstrates expertise in utilizing popular Python frameworks like Django and Flask, along with data analysis and manipulation libraries such as NumPy and Pandas. On the front-end, Ishaan adeptly employs JavaScript libraries like React and Angular to craft visually appealing and user-friendly interfaces. Additionally, he possesses proficiency in HTML, CSS, and JavaScript for designing responsive and mobile-friendly layouts.