What git
aliases do you use? Why do you like them?
For further actions, you may consider blocking this person and/or reporting abuse
What git
aliases do you use? Why do you like them?
For further actions, you may consider blocking this person and/or reporting abuse
Samuel K.M -
ProDev. Staff -
Best Codes -
Balraj Singh -
Top comments (16)
An alias to show my aliases:
alias.alias config --get-regexp ^alias\.
An alias to make a branch, with a date suffix:
alias.mkbr !f(){ local args="$*"_; local gituser=$(git config user.email); gituser=${gituser%@*}; if [ "$args" = "_" ]; then args=""; fi; args=${gituser:-${USER}}/$args$(date "+%Y-%b-%d"); args=$(echo "$args" | tr ' [A-Z]' '_[a-z]'); git checkout -b "$args"; };f
An alias to delete a branch:
alias.rmbr !f(){ git branch -d "${1}"; git push origin --delete "${1}"; };f
An alias to go to master:
alias.master checkout master
An alias to get coffee:
alias.coffee !f(){ if [ $(date -j +%a) = 'Fri' ]; then echo 'Friday! Time for beer!'; else echo 'Time for a coffee break. Go get a cup of joe.'; fi };f
An alias for a quick status:
alias.st status -s -uno
An alias to do a diff with my configured difftool:
alias.d difftool
An alias to use kdiff3 to display my changes in my branch from master:
alias.d3master difftool --tool kdiff3 --dir-diff origin/master..
A bash shell alias to do a git log of just the branch's first parent:
alias log=git log --pretty=oneline --graph --max-count=$(( $LINES / 2 )) --first-parent --use-mailmap --date=format:%Y-%b-%d\ %H:%M --pretty=format:'\''%C(red)%h%C(reset) -%C(yellow)%d%C(reset) %C(green)%cd %C(bold blue)%aN%C(reset) %s'\'' --abbrev-commit
I'd suggest dropping the
-j
on yourdate
command. It doesn't need to be there because you're not setting a date, and it's not compatible with GNU date, so it won't work on 99% of servers.Here is my list of
git
aliasI really like these:
get = !git pull --ff-only
- lets me rungit get
to only pull fast forward changeswho = shortlog -n -s --no-merges
- this is more of a fun one. Shows a list of who has committed to the project and how many commits they have madeA complicated one
This requires
fzf
to be installed but allows you to fuzzy find and check out a git branch. Really useful when you don't remember the branch name exactly but have an idea of what it might be.Here are mine:
Shorthand for using git (bash/zsh alias):
alias g=git
Undo the last commit:
undo = reset --soft HEAD^
Get a summary of commits since yesterday (useful during standups):
standup = !"git log --reverse --branches --since=$(if [[ "Mon" == "$(date +%a)" ]]; then echo "friday"; else echo "yesterday"; fi) --author=$(git config --get user.email) --format=format:'%C(cyan) %ad %C(yellow)%h %Creset %s %Cgreen%d' --date=local"
Push to origin:
pp = push origin
Force push to origin:
ppf = push origin --force-with-lease
Pretty log:
lol = log --pretty=format:"%C(yellow)%h\\ %Cblue%G?%Cred%d\\ %Creset%s%Cgreen\\ (%cr)%Cblue\\ [%cn]" --decorate --graph
This is a must have on my
.bashrc
:These are from the oh-my-zsh git plugin:
github.com/robbyrussell/oh-my-zsh/...
Not strictly a git alias, but I have a bash alias
gclone <repo>
that clones the repo andcd
s into the directory.This is disgusting and I don't recommend it, but I compile my Linux kernels from source when they are released on my Gentoo system:
Must be run as root, and assums the user has already utilized
eselect kernel
to chose their desired kernel version. This symlinks the source tousr/src/linux
.This was my "first draft" and now its years later and I've been using it about once a week without touching it. I have a similar shindig for cleanup of old kernel artifacts but I couldn't quite pack it into an alias, it's got its own function.
I keep feeling like i should revisit this whole setup but it...keeps working fine.
Here's mine.
My Git Aliases
Nick Taylor ・ Aug 25 '18 ・ 5 min read
alias gpc='git push --set-upstream origin "$(git-branch-current 2> /dev/null)"'
if you don't have anything, this would suffice alone. i always forget how to push my new branch to remote...