What are Git aliases
Have you ever wondered if you could skip typing git add /path/to/filename && git commit "my message" && git push
? That’s what git aliases are for.
How to create an alias
Using the git config
command, we can declare globally the aliases. For example:
1
|
git config --global alias.todo "! git grep --extended-regexp -I --line-number --break --heading --color=auto 'TODO|FIXME'"
|
What are example of aliases that can be helpful
My aliases
Add via direct git config edition
1
|
git config --global --edit
|
Add via CLI
1
2
3
4
5
6
7
8
9
10
11
|
## List existing aliases
git config --global alias.alias "! git config --get-regexp alias"
## Hard reset
git config --global alias.hr "! git reset --hard HEAD"
## Soft reset
git config --global alias.sr "! git reset --soft HEAD^"
## Hard reset and pull
# Can't add the following.
# Maybe edit the git config file directly as the alias should work...
# Maybe an escape issue?
git config --global alias.hrp "!f() { git hr && git pull }; f"
|
What are my aliases
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
[alias]
conf = ! notepad /c/Users/Jeremiel/.gitconfig
#conf = ! git config --global --edit
ac = ! git add -A && git commit -m
acc = ! git add $1 && git commit -m "$2"
alias = ! git config --get-regexp ^alias\\. | sed -e s/^alias\\.// -e s/\\ /\\ =\\ /
sr = ! git reset --soft HEAD^
hr = ! git reset --hard HEAD
ceb = ! git checkout -t
cb = ! git checkout -b
c = ! git checkout
rpm = ! git hr && git checkout main && git pull
mm = ! git merge main
bv = ! bash bump-site-version.sh
t = ! git tag -a
tp = ! git push origin ```
#For VuePress publishing
pub = ! npm run docs:build && git push
dev = ! npm run docs:dev
build = ! npm run docs:build
|
Articles I read while researching the topic
https://bitbucket.org/durdn/cfg/src/master/.gitconfig?at=master
https://www.durdn.com/blog/2012/11/22/must-have-git-aliases-advanced-examples/
https://www.atlassian.com/blog/git/advanced-git-aliases
https://stackoverflow.com/questions/3321492/git-alias-with-positional-parameters
https://borntocode.fr/git-alias-etre-un-bon-developpeur-faineant/