Where to find git config file in Mac:
In Mac, you can usually find the Git config file in your home directory, in hidden file .gitconfig
eg., /Users/.gitconfig
How to Add alias(aliases) to Git config file:
You can add Aliases for GIT commands (a single command or a series of commands) for your convenience (easy to remember or fewer keyboard strokes)
Couple ways to add alias to the config file:
-
- Add using git config command: eg., here is to add alias to find the Last commit to the branch you are on.
git config --global alias.last 'log -1 HEAD'
- Add the entry manually in the .gitconfig file itself. The same example can be written in the config file. Just add the below lines to the end of the config file if there is no [alias] tag in the file already, or if there is a [alias] tab already, add the alias as key value pair.
[alias]
last = log -1 HEAD
If you want the list of files that are committed, add the flag ‘–stat’.
[alias]
last = log --stat -1 HEAD
Â
And the command you use to execute the alias is much like how you use other git commands.
git last
Also if you want to add an alias which takes a parameter, here is how to add git alias with a parameter.
Lets say we want to create a branch, and want to use a shorter command (‘cb’) instead of checkout.
you give an alias ‘cb’ with the actual command, wrapped in a function that takes a parameter.
[alias]
cb = "!f() { git checkout -b $1;}; f"
And you can execute ‘git cb {branch_name_you_want_to_create}
‘ to create the git branch.
Feel free to provide comments/suggestions.