-
-
Save teserak/771fa7a4c98b4679565e26a2c9fa637d to your computer and use it in GitHub Desktop.
Git Aliases to make GIT easier to work with
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[user] | |
email = your_email | |
name = your_username | |
[alias] | |
# git clone | |
cl = !git clone | |
# Git shallow clone for large repos | |
clq= !git clone --depth=1 | |
s = status | |
co = checkout | |
cob = checkout -b | |
feat = "!f(){ git cob feature/${1}; };f" | |
# Return the default branch for the repo i.e. master or main | |
default = !git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@' | |
del = branch -D | |
br-clean = "!f() { DEFAULT=$(git default); git branch --merged ${1-$DEFAULT} | grep -v " ${1-$DEFAULT}$" | xargs git branch -d; }; f" | |
br = branch --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(contents:subject) %(color:green)(%(committerdate:relative)) [%(authorname)]' --sort=-committerdate | |
save = !git add -A && git commit -m | |
undo = reset HEAD~1 --mixed | |
# Saves work in an unreachable commit, just in case, THEN WIPES it from existance | |
wipe = !git add -A && git commit -qm 'WIPE SAVEPOINT' && git reset HEAD~1 --hard | |
done = "!f() { DEFAULT=$(git default); git checkout ${1-$DEFAULT} && git up && git br-clean ${1-$DEFAULT}; }; f" | |
# Pretty log | |
logs = !git log --pretty=format:\"%C(magenta)%h%Creset -%C(red)%d%Creset %s %C(dim green)(%cr) [%an]\" --abbrev-commit -30 | |
last = log -1 HEAD | |
cm = commit -m | |
ci = commit | |
st = stash | |
pop = stash pop | |
apply = stash apply | |
# get config info i.e. git conf user.name | |
conf = config --global | |
# quick work-in-progress commit | |
wip = commit -am "WIP" | |
# change commit message | |
amend = commit -a --amend | |
# Squash the last N commits. git squash 3, will reset the last 3 commits to the working directory then save them in a new commit | |
squash = "!f(){ git reset --soft HEAD~${1} && git commit --edit -m\"$(git log --format=%B --reverse HEAD..HEAD@{1})\"; };f" | |
# unstage file(s) | |
unstage = restore --staged | |
## sync current feature branch with origin/develop | |
syncod = !git fetch --all && git merge origin/develop | |
## sync current feature branch with given origin branch | |
sync = "!f(){ git fetch --all && git merge origin/${1}; };f" | |
# checkout develop branch | |
dev = !git checkout develop | |
# checkout the default branch i.e. master or main | |
ma = "!f() { DEFAULT=$(git default); git checkout ${1-$DEFAULT}; }; f" | |
master = !git checkout master | |
main = !git checkout main | |
dev = !git checkout develop | |
up = !git pull --rebase --prune $@ && git submodule update --init --recursive | |
# remove .git folder, maybe you `git init` in the wrong place | |
uninit = !rm -rf .git | |
[push] | |
default = current | |
# automatically setup remote branch tracking without --set-upstream-branch | |
autoSetupRemote = true | |
[pull] | |
default = current |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment