I went to the other extreme. I have a somewhat elaborate fish function which detects any use of -a and refuses to call Git with it.
I had gotten lazy about good commits, basically, `git commit -a` was in my muscle memory. Forcing myself to treat staging as a step before committing, and getting in the habit of using `git add -p` when called for, has made a meaningful difference in the quality of my commit history.
If one is disciplined about making changes in the first place, I suppose this matters less. But I'm not, and also don't want to be: if I spot something else which needs doing while I'm in flow mode, I'm not going to put it off just to keep commits nice, not when there are better options for doing that part.
I make one elaborate commit where I carefully stage things etc. But invariably I miss something, find 3 typos and so on.
that’s when the aliases are handy. The alias for fixing a typo is using all, amend and no-edit. Super useful. But obviously needs to be used with care when you only do such a fix. I’d be perfectly happy for my git oops to refuse running if there is more than one changed line to commit, for example.
My git status is `git s` aliased to `git status -sb`, don't need all the extra clutter.
I also have a few .zshrc aliases, like `gap` which is `git add -p` or `gam` which is `git commit --amend --no-edit`.
But also some typo fixing ones that I end up doing a lot, some because I type in half a command and get distracted / check something, then start over with a partially filled in command:
alias gigit="git"
alias gitgit="git"
alias ggit="git"
alias qgit="git"
alias ght="git"
alias got="git"
alias cleear="clear"
alias gits="git s"
Another trick, in your .gitconfig, add this [alias]:
git = !git
That way, if you accidentally do `git git commit` or whatever (like above) it just works. Also, some typo fixes there:
- `ls` for `ls-files`
- `lo` for `git log --oneline`, then add a variety of letters in multiple combinations like
- `r` for `--reverse`,
- `s` for `--stat`,
- `om` for `origin/master..`,
- `1` for `-n1`, `2` for `-n2`, `3` for `-n3` (maybe up to 5),
- `rbi` for `rebase -i`,
- `rbiom` for `rebase -i origin/master`,
- `rbc` for `rebase --continue`
- `rba` for `rebase --abort`
- `cp` for `cherry-pick`,
- `cpa` for `cherry-pick --abort`,
- `cpc` for `cherry-pick --continue`
I also have _shell_ aliases like `gits` that works out to `git status -uno`, and `gita` that lets me add tracked files. I need a `gitca` for `EDITOR=true git commit --amend`.
Notice I don't have aliases for merging. I use strictly rebase and cherry-pick workflows.
I found these online and added them to my gitconfig at one point... I can't take credit for them. Integrating fzf with git makes working with branches even better (with fuzzy matches for checking out as well as deleting branches)...
It’s strange that git aliases can’t accept multiple git commands. It gives a strange divide between single command aliases which go in your git config and multi command aliases which go in a shell config. Shells vary and some don’t even have aliases (cmd is probably the most used shell of them all and it - almost - doesn’t have aliases at all).
Being able to define an && alias in .gitconfig would be great for being able to share snippets like these across shells and OS:es.
My most used alias is by far “git oops” for git commmit —all —-amend —-no-edit
> But git was written assuming a posix shell and it shows up here and there sadly.
Given that the entire point of POSIX is cross platform compatibility, this is one of the few times when I will say they (Linus/git) got it 100% right.
> Should be possible for git to simply interpret sequentially.
Simply? What should it do if the first command fails? Should it exit early? What if you want it to run the second only if the first returns error? What if you want to pipe the first to the second? Or use it as an argument?
Aliases have a "simple" mode where they call exactly one thing. Anything beyond that can't be simple, without also being useless.
If Microsoft can't ship a POSIX compatible shell that's on them, and if you insist on using an OS that doesn't have a POSIX compatible shell, that's on you.
I don't start Linux and ask why it doesn't run whatever people use Windows for... malware I assume?
> Simply? What should it do if the first command fails? Should it exit early? What if you want it to run the second only if the first returns error?
You’d eventually reinvent a shell. But for just these 2 cases you’d just need 2 separators analogous to the & and && of the shell. But yeah it gets messy if you wanted to run a non git command in the middle.
The thing is, all those !a && b are perfectly valid in both posix and cmd. It just refuses to do the whole “if it starts with ! call the shell”. I guess all that’s missing is that it just needs to execute it. That would probably be the less complicated change. That at least doesn’t seem like a big controversial addition (maybe this is already done now it was a couple of years since I tried and hit a brick wall with aliases under cmd)
# https://stackoverflow.com/questions/4298960/git-add-a-git-co...
git config --global alias.ac '!git add -A && git commit'
git config --global alias.acm '!git add -A && git commit -m'
git config --global alias.ll '!git log --graph --full-history --all --color --pretty=format:"%x1b[31m%h%x09%x1b[32m%d%x1b[0m%x20%s"'
git config --global alias.gst '!git status'
git config --global alias.gca '!git commit -a --amend'
git config --global alias.gp '!git push origin HEAD'
git config --global alias.bd '!git branch -d'
git config --global alias.bdd '!git branch -D'
git config --global alias.mc '!git diff --name-only --diff-filter=U'
git config --global alias.co '!git checkout'
git config --global alias.po '!git push origin'
git config --global alias.cp '!git add -A && git commit -m "Content" && git push'
Out of those, I only – but often – use `git acm` and `git co` and `git po`.
Edit: formatting (oh dear).