jswanner
I was about to reply to Why doesn’t Phoenix use Conventional Commit prefixes? - #41 by sodapopcan with some git aliases that I use for things like amending and rebasing commits, but then I thought it would be better to have a separate topic for that discussion, so here we are.
These are some git aliases I use frequently:
amend = commit -v --amend
fixup = !sh -c '_c=$(git rev-parse "$0") && git commit --fixup "$_c" && git rebase --autosquash --autostash --interactive "$_c"^ && unset _c'
force-push = push --force --force-with-lease
intend-to-add = add --intent-to-add
pop = stash pop
Most of these are for saving a few key strokes, for git commands I use extremely frequently (like git status -sb and git commit -v), I have fish shell abbreviations for those that are just 2-3 characters long.
The fixup alias above I find quite useful. It uses git rev-parse so that way the commit to be fixed can be specified by (partial) sha or something like HEAD~3, it’ll then commit what’s staged as a fixup commit and finally start an interactive rebase where most of the time nothing else needs to be done but to confirm.
I have other aliases for things like different formats of git log --all --graph but honestly I don’t use them that much.
Some other settings that I recommend:
[core]
pager = $(brew --prefix git)/share/git-core/contrib/diff-highlight/diff-highlight | LESSCHARSET='utf-8' less -F -R -X
[branch]
sort = -committerdate
[rerere]
enabled = true
Trending in Dev Env & Tools
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #blog-post
- #phoenix_html
- #iex
- #graphql
- #ai
- #genstage
- #elixirconf-us
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #metaprogramming
- #security
- #hex










First 10 of 22 Posts
adamu
This creates a bash function
g, forgit, which defaults togit statuswhen there are no arguments.rhcarvalho
You might like this GitHub - torbiak/git-autofixup: create fixup commits for topic branches · GitHub
I alias it
git af.sodapopcan
nit: You don’t need the
--forcehere.This is a good idea! I feel this should really be the default of
gitas showing help isn’t that helpful as most people know how to get help (and are probably looking online anyway).My
gis a function that creates a git repo:I otherwise don’t have much to contribute here as I do the vast amount of my gitting in fugitive.vim. I have a couple of pretty uninteresting aliases like
gsfor git status (which happens also be my vim mapping to open the fugitive status window!) It finally bit me for the first last year when I actually wanted to experiment with ghost script for my job, but then I found out you can bypass aliases by prefixing them with a\so it worked as a learning momentsodapopcan
Oh! One little trick that it seems a lot of people don’t know (my data is my coworkers) is that instead of
HEAD~N, you can just spam^which I find easier to type. SoHEAD~3can also be written asHEAD^^^. You can put as many as you want, it’s kinda funny in a wayAlso,
HEADdoesn’t need to be written in caps anymore. It can also be written as@, though I find that more annoying to type on my keyboard thanhead.jswanner
Yeah, I know, it’s a holdover from a time when you actually needed to have both flags, as
--force-with-leasedid not imply--force.sodapopcan
Oh interesting, I did not know that!
matt-savvy
If you use Oh My Zsh, there’s a gold mine of aliases at your fingertips.
Two personal aliases that I use all the time:
glm- See the commits for the current branch since it branched off frommaster.gccp- Copy the current (short) commit hash to the clipboard (pbcopyusually only on OSX, replace withxclipor whatever else you use if needed).I use this when making changes on a Pull Request. It’s super helpful to respond to a comment and include the commit hash with makes the change being discussed. Github automatically turns this text (if the commit exists on GH) into a link to the commit, making it super easy for followup reviews, etc.
sodapopcan
Sorry I forgot to respond to this—I was too busy having a mini heart attack over the inline types thread
I’ve never used ommyzsh but I did used to have that mapping! I got rid of it once I realized I wanted to it across other branches as well. I generally don’t have very many aliases at but I do I have
glforgit logwhich is quite long:So now I just do
gl main...jswanner
Does shell completion work with these functions?
sodapopcan
I never even thought to try but yes! Well, autocompletion doesn’t make sense for my
galias as I’m always creating a directory that doesn’t exist, but ya, I just triedgland ya it all works.