Skip to main content

Git aliases

Why do I need it? This instructions set can decrease time of typing git commands and increase you productivity while development process.

How can I use it? Open your /Users/youruser/.gitconfig file and paste there the code below

*Note: before using new commands you need to create 'git-alias-helper' branch

[alias]
chekcouttohelperbranch = "!f() { git checkout git-alias-helper; };f"
rsh = "!f() { git reset --soft HEAD~${1}; };f"
acp = "!f() { git add . && git commit -m \"${1}\" && git push -u origin \"$(git rev-parse --abbrev-ref HEAD)\"; };f"
revapp = "!f() { git reb && git commit --allow-empty -m "review-app" && git push --force; };f"
acpr = "!f() { git acp ${1} && git revapp; };f"
ac = "!f() { git add . && git commit -m \"${1}\"; };f"
refresh = "!f() { git chekcouttohelperbranch && git branch -D ${1} && git fetch origin ${1} && git checkout ${1}; };f"
d = "!f() { git branch -D ${1}; };f"
reb = "!f() { git fetch origin master && git rebase origin/master; };f"
ra = "!f() { git rebase --abort; };f"
refm = "!f() { git refresh master; };f"
refs = "!f() { git refresh staging; };f"
refswithmerge = "!f() { git reb && echo merge $(git rev-parse --abbrev-ref HEAD) | pbcopy && git refs && git merge ${1} --squash; };f"
refawithmerge = "!f() { git reb && echo merge $(git rev-parse --abbrev-ref HEAD) | pbcopy && git refa && git merge ${1} --squash; };f"
refa = "!f() { git refresh alpha; };f"
mrgs = "!f() { git refswithmerge $(git rev-parse --abbrev-ref HEAD); };f"
mrga = "!f() { git refawithmerge $(git rev-parse --abbrev-ref HEAD); };f"
new = "!f() { git refm && git checkout -b ${1}; };f"
rac = "!f() { git add . && git rebase --continue; };f"
pul = "!f() { git pull origin $(git rev-parse --abbrev-ref HEAD); };f"
cp = "!f() { git cherry-pick ${1}; };f"
cb = "!f() { git checkout -b ${1}; };f"
sp = "!f() { git stash pop; };f"
nukes = "!f() { git branch -D staging && git new staging ; };f"
nukea = "!f() { git branch -D alpha && git new alpha ; };f"
fmrg = "!f() { git fetch origin ${1} && git merge origin/${1} --squash; };f"
co = checkout
s = status
uncommit = reset --soft HEAD^

[push]
default = current

How does it works? If you look at this alias com = "!f() { git commit -m \"${1}\"; };f" you can see com which is name of your alias, !f() { ;};f - function of alias, need this to use incoming arguments git reset --soft HEAD~${1} - your git command ${1} - first argument of alias function

Descriptions:

rsh = "!f() { git reset --soft HEAD~${1}; };f" // remove some number of commits, e.g. git rsh 2
com = "!f() { git commit -m \"${1}\"; };f" // short alias for commit
acp = "!f() { git add . && git commit -m \"${1}\" && git push -u origin \"$(git rev-parse --abbrev-ref HEAD)\"; };f" // alias for add, commit and push with commit message, e.g. git acp "you commit message"
revapp = "!f() { git commit --allow-empty -m "review-app" && git push -u origin \"$(git rev-parse --abbrev-ref HEAD)\"; };f" // review-app commit
ac = "!f() { git add . && git commit -m \"${1}\"; };f" // alias for add and commit
refresh = "!f() { git branch -D ${1} && git fetch origin ${1} && git checkout ${1}; };f" //removes selected branch and fetches last version from gitlab
d = "!f() { git branch -D ${1}; };f"
reb = "!f() { git fetch origin master && git rebase origin/master; };f" // rebase master
ra = "!f() { git rebase --abort; };f"
refm = "!f() { git refresh master; };f" // get latest version of master
refs = "!f() { git refresh staging; };f" // get latest version of staging
refa = "!f() { git refresh alpha; };f"
mrg = "!f() { git refs && git merge ${1} --squash; };f" // get latest staging and merge your branch with squash
new = "!f() { git refm && git checkout -b ${1}; };f" // create new branch from latest master
rac = "!f() { git add . && git rebase --continue; };f"
pul = "!f() { git pull origin $(git rev-parse --abbrev-ref HEAD); };f"
cp = "!f() { git cherry-pick ${1}; };f"
cb = "!f() { git checkout -b ${1}; };f"
sp = "!f() { git stash pop; };f"
nuke = "!f() { git branch -D staging && git new staging ; };f" // for nuking staging
co = checkout
s = status
uncommit = reset --soft HEAD^
mrgs: merges you current branch to staging with rebasing with master and copy branch name to the buffer
mrga: the same as ‘mrgs’ but for alpha