This is my personal git aliases I use. Some I picked up, some created and some stolen from durdn (Check him out. He has a lot of cool aliases that don't fit my use cases but might fit yours).
Feel free to read through them in .gitconfig (I gave a description for some of them in #What they do?). Or go straight to adding them to your config file.
Most of them are simple shortcuts
ci = commit
cl = clone
br = branch
Some with parameters or sub commands
cian = commit --amend --no-edit
cob = checkout -tb
st = status -sb
sl = stash list
po = push -u origin HEAD
update master/main
checkout master or main (which ever is present) and pull
Expanded:
!(git checkout master || git checkout main) && git pull -r
ls aliases
Expanded:
!git config -l \| grep ^alias \| cut -c 7- \| awk -F= '{first=$1;$1=\"\";printf(\"%-12s %s\\n\",first,$0);}'"
Output:
$ git lsa
ci commit
cia commit --amend
cian commit --amend --no-edit
cim commit -m
co checkout
cob checkout -tb
st status -sb
cl clone
br branch
r reset
cp cherry-pick
gr grep -Ii
s stash
sl stash list
sa stash apply
ss stash save
lasttag describe --tags --abbrev 0
lt describe --tags --abbrev 0
p push
po push -u origin HEAD
um !(git checkout master || git checkout main) && git pull -r
lsa-raw !git config -l | grep ^alias | cut -c 7-
lsa !git lsa-raw | awk -F '{first $1;$1 "";printf("%-12s %s\n",first,$0);}'
lsal !git lsa-raw | awk -F '{first $1;$1 "";printf("%12s %s\n",first,$0);}'
qc !f() { git stash && git um && git co -tb "$1" && git stash pop && git add . && git ci -m "${1}: ${2}" -m '' -m "${3:-desc}"; } ; f
empty !git commit -am"[empty] Initial commit" --allow-empty
lightclone !echo -e "!--------------------!
lc lightclone
logg log --graph --oneline --decorate
logga logg --all
lg log --color --graph --pretty format:'%C(yellow)%h%Creset -%C(cyan)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
lga lg --all
glsa !git lsa | grep
Alternatives:
-
git lsa-raw
: no formatting -
git lsal
: left padding for the alias namelg log --color --graph --pretty format:'%C(yellow)%h%Creset -%C(cyan)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit lga '!git lol --all'
-
git glsa
: lsa with grep$ git glsa lsa lsa-raw !git config -l | grep ^alias | cut -c 7- lsa !git lsa-raw | awk -F '{first $1;$1 "";printf("%-12s %s\n",first,$0);}' lsal !git lsa-raw | awk -F '{first $1;$1 "";printf("%12s %s\n",first,$0);}' glsa !git lsa | grep
quick commit
Parameters:
- Feature Name/Ticket Name: used in branch name and commit message
- Commit message (optional)
- Commit Description (optional)
Expanded:
"!f() { git stash && git um && git co -tb \"$1\" && git stash pop && git add . && git ci -m \"${1}: ${2}\" -m '' -m \"${3:-desc}\"; } ; f"
Buckle Up!
- stash
- checkout and update master (git um)
- create a new branch with the given ticket name
- pop stash
- add all
- commit using parameters
light clone
alias: git lightclone
Only use this for checking out a repo you just found. Using depth
when cloning a repo for development can lead to unexpected behavior.
Expanded:
echo XXXX && git clone --depth 10 --single-branch
Example:
Normal:
$ git clone https://github.com/facebook/react.git
Cloning into 'react'...
remote: Enumerating objects: 215295, done.
Receiving objects: 17% (37309/215295), 40.29 MiB | 3.07 MiB/s
# ctrl c
light clone:
$ git lc https://github.com/facebook/react.git
!--------------------!
Depth is set to 10!
Can lead to UNEXPECTED behaviour.
Useful if you are only checking out repo, not using it for development
!--------------------!
Cloning into 'react'...
remote: Enumerating objects: 2827, done.
remote: Counting objects: 100% (2827/2827), done.
remote: Compressing objects: 100% (2334/2334), done.
remote: Total 2827 (delta 699), reused 1043 (delta 383), pack-reused 0
Receiving objects: 100% (2827/2827), 5.91 MiB | 656.00 KiB/s, done.
Resolving deltas: 100% (699/699), done.
log
git log
with custom formatting (one liners, relative time from commit, author name).
Expanded:
log --color --graph --pretty=format:'%C(yellow)%h%Creset -%C(cyan)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
Output:
You can either copy the content of .gitconfig to your ~/.gitconfig
. Or execute add_aliases.sh to add them to your ~/.gitconfig
.
To learn more about how the add_aliases.sh was generated, Checkout Github Action section.
uses update_aliases.sh to update add_aliases.sh on push.
Steps:
- Checkout code.
- Generate a new add_aliases.sh script from .gitconfig using update_aliases.sh.
- Compare the newly generated add_aliases.sh file with the one already present.
- If there's a difference
- Replace old add_aliases.sh with the updated one
- Commit the update.