Git aliases can significantly improve your workflow by providing shorthand commands for frequently used operations. Below is a step-by-step guide to configure Git aliases and set your Git user name and email.
It's essential to set your Git user name and email globally so that commits are properly attributed to you.
-
Open your terminal and run the following commands:
git config --global user.name "Your Name" git config --global user.email "your.email@example.com"
-
Verify the configuration:
git config --global --list
You should see your name and email listed in the output.
Add the following aliases to your Git configuration to speed up common tasks:
[alias]
s = !git status -s
c = !git add --all && git commit -m
co = !git checkout
l = !git log --pretty=format:'%C(blue)%h%C(red)%d %C(white)%s - %C(cyan)%cn, %C(green)%cr'
set = !git push --set-upstream origin "$(git symbolic-ref --short HEAD)"
newMaster = !git branch -D master && git checkout master && git pull && git checkout -b
newMain = !git branch -D main && git checkout main && git pull && git checkout -b
-
Open the Git configuration file in your editor:
git config --global --edit
-
Copy and paste the alias block above under the
[alias]
section. -
Save and close the file.
Now you can use these aliases directly in your terminal, e.g., git s
for a short status or git c "Commit message"
to stage all changes and commit them with a single command.
-
Global vs Local Configuration: The
--global
flag applies the configuration to all repositories on your machine. To set these settings for a specific repository, omit the--global
flag and run the commands in the repository's directory. -
Editing Configuration Directly: You can edit the global configuration file manually:
nano ~/.gitconfig
This file contains all your global settings, including aliases and user information.
With these steps, you'll have a more efficient Git workflow and properly attributed commits!