Leveraging aliases when working with git can help make you more efficient with using the popular version control system. Listed below are some of m...
For further actions, you may consider blocking this person and/or reporting abuse
This also acts as sort of a cheatsheet for things you might want to be doing in the first place, while giving a more compact command to do so.
Not everybody loves aliases, but this looks like a great guideline for those who do or want to start.
This is true. I worked with a guy that refused to use aliases because he thought he would forget the underlying command behind the alias.
It’s less that and more having your muscle memory be completely wrong as soon as you ssh somewhere.
Aliases are ok... but anyone with a bloated vimrc file can tell you how strange it feels to use the defaults. (Seriously, using vim-surround is basically the main reason I still use vim)
EDIT: and typing git commands are a very small part of my workflow, so it seems wasteful to alias them. And I will absolutely never
add -A
... I’m too paranoid about committing something I didn’t mean to.I don't have many aliases for git commands but seeing
git add -A
has inspired me to add one more to my small list:alias gip='git add ${FILE} -p'
As in:
git add file.rb -p
. The-p
flag tells git that you want to select which individual lines/hunks get committed. It's the scalpel to-A
's mallet.The alias allows me to do it this way:
gip file.rb
SInce i work in feature branches that get squash merged in a few days, I don’t really understand why you would be doing more than one thing at once...
I don't think squash merge should exist. The commit message sucks, many times your feature can be good individual changes (valuable outside the feature) it is pretty easy to finalize the order and squash with a rebase --interactive.
I'm said --fixup isn't listed as as alias.
My general opinion is very much 'use whatever works best for you'.
For me personally though, aliases like this are equivalent to improving the speed/performance of your car by speeding up how quickly you can get into and out of the car.
Haha, that's why I bookmarked it. Apart from
add
,commit -a -m
,push --all
and branching I do nothing else. And that I think is powerful, I only imagine how much power I'd get if I could be bothered learning the rest.My favorites are:
Both funny examples. My favorite (when needed) is
git rip-history
(force-push).Other than that, I only have a couple that are useful for my workflow.
One that I haven't seen elsewhere is this:
git email
(git config --global user.email
).Also, I realized while typing this that yours were bash aliases like above. I still haven't made the transition from git aliases...
Oh wow. You made WAY more than me. I did this a while back, my aliases are;
push (git push),
pull (git pull),
add (git add *),
commit (git commit -m),
check (git checkout),
branch (git branch)
That's about all I ever use/felt comfortable aliasing. I also didn't go to the same level of abbreviation as you. But I enjoyed your list, was fun to see how somebody else chose to implement the same idea.
Thank you for an in-depth list of common git commands. If I weren't on Windows I might be using some of them. (
gl
especially)Using aliases is fine for the most part. Just so that people don't jump directly into using them, here are some downsides to this:
Overall, I think you should try it for the most used commands (like
status
,commit
andpull
), it definitely saves up some time.You can use aliases on Windows? That surprises me.
Apparently, you can.
I use git aliases and they are good enough for me... I just don't want to deal with batch... shivers
Interesting list of aliases you have - some are similar and some quite different than mine. I tried so stick with a two-character rule though.
you could try to use capitalisation to further shorten the necessary keystrokes a bit.
For example i use
ga
forgit add <file>
andgA
forgit add --all
.Nice, I like that
I rely on git aliases rather than shell aliases, and I try not to go overboard with the amount of aliases either.
I use YADM to manage my dotfiles and since it wraps git it will automatically pick up on git aliases, e.g
yadm alias
is the same asgit alias
, but I couldn't doyadm zsh-alias
.Shortening some commands is highly useful if I do them a lot, but if I write a bunch of aliases for nearly everything I've replaced learning git commands with learning git aliases. It's increasing my mental workload instead of easing it because I have to memorize the alias and what it stands for.
I also have to use other VCS sometimes, and by retaining the git prefix on git commands I find it's easier to remember what is what since terminology is similar but not identical between VCS.
I haven't heard of YADM before you mentioned it. I will look into it since I don't have a solution to manage all of my dotfiles yet.
There's a whole bunch of options in that space, but I prefer the simplicity and straightforwardness of YADM. It's basically just a wrapper around git allowing you to track files without making an actual repository, i.e. it only cares about files you manually add to it so a
yadm status
won't list dozens of unrelated files and folders.It also imposes no restrictions on folder structure etc.
The one that I use a lot (I've got it as a shell script rather than as an alias or function) is ...
Just stumbled upon this one -- great job!
I've been using similar aliases over the past few years. Here's what works for me (someone may relate and adapt accordingly):
I wouldnt use bash aliases for the commands, just for git itself. That way you keep tab completion on the aliases.
For example:
g l
=g log --pretty=oneline --graph
g caa
=g commit -a --amend
The
g
is a normal bash aliasTab completion still works for me when I use zsh aliases.
Definately you are not a lot or not at all productive with aliases, if the commands are small and used rarely, like the git is.
Plus the cognitive load is bigger, because u still have to learn the underline commands when u need more custom params, so is only a new layer of complexity in your head.
You can save 10s per day with alises and waste 1h for a debuging that could be avoided.
I use a limited amount of aliases but I removed my own and switched to a popular framework called github.com/Bash-it/bash-it
Doesn't aliasing break tab-complete? I don't always remember the branches of the projects and how I called them, so I sometimes really do have to rely on git telling me.
Tab completion still works for me! For example I can use
gco
(forgit checkout
) and start typing a branch name and then use tab completion to find the branch i'm looking for.Here is a file soyou don't have to write it yourself. No garantuees, haven't testet all of them yet:
gist.github.com/MrMovl/b8d3f390e3c...
Good idea, thanks!
Thanks Stefan, I appreciate it 👍
Aliases make me forget actual commands :D
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative
For a graphic history
I like aliases, but this post encouraged me to write about the other side of the coin:
The case against aliases
Ben Sinclair
Nice! It's always good to look at things from another perspective like this.
Emmet for git :)
Amazing list 👍
Very nice list though I skip on aliasing
git rebase --abort