If you are using Zsh on macOS, you can create functions in your ~/.zshrc
file to automate the repetitive Git commands you mentioned.
To get started, open your terminal and execute the following command to open the ~/.zshrc
file in a text editor:
open ~/.zshrc
This will open the ~/.zshrc
file in the default text editor configured on your system.
Add the following functions to the file:
function gitinit() {
git init
git add .
git commit -m "$1"
git branch -M main
git remote add origin $2
git push -u origin main
}
function gitcommit() {
git add .
git commit -m "$1"
}
function gitpush() {
git add .
git commit -m "$1"
git push origin main
}
Save the file and exit the text editor.
To apply the changes and make the functions available in your current terminal session, you can either restart your terminal or run the following command:
source ~/.zshrc
Afterward, you can simply use these functions to automate your Git workflow. For example:
gitinit "Initial commit" git@github.com:your-username/your-repo.git
gitcommit "Added new feature"
gitpush "Pushing latest changes"
These functions will execute the corresponding Git commands with the provided arguments.
Make sure to replace your-username
and your-repo
in the gitinit
function call with your actual GitHub username and repository name.