Skip to content

Instantly share code, notes, and snippets.

@gidgid
gidgid / .gitconfig
Created October 10, 2019 19:57
Shows my adds and checkouts in Gitconfig
[alias]
# Adding files
## "add untracked" - no untracked files
au = add -u
## "add all" - add everything. https://stackoverflow.com/questions/572549/difference-between-git-add-a-and-git-add
aa = add -A
## "add patch" - choose what to add
ap = add -p
# Checkouts
@gidgid
gidgid / shell
Last active October 12, 2019 20:15
Using Gitconfig basic aliases
# add all files except untracked
$ git au
# add all files
$ git aa
# you can use it to add all the contents of a specific directory
$ git aa <dirname>
# add patch
$ git ap <filename>
# checkout & create a new branch
$ git cob <new-branch-name>
@gidgid
gidgid / .gitconfig
Last active November 7, 2019 10:23
More aliases
[alias]
# commits
## show me my diff while writing the commit message
ct = commit --verbose
## "commit add" add all files then commit
cta = commit -a --verbose
## amend is slightly long but it felt natural this way
amend = commit --verbose --amend
## you can combine actions like this:
## "add amend" - first add, then amend
@gidgid
gidgid / .gitconfig
Last active October 13, 2019 13:42
Showing Git checkout by regex
[alias]
# checkouts
## "checkout regex" - more or less checkout branches by regex
cor = "!checkout_by_regex() { git checkout $(git branch | grep -e \"$1\" | head -n1); }; checkout_by_regex"
@gidgid
gidgid / .gitconfig
Last active October 13, 2019 13:42
Git aliases with FZF
[alias]
# more aliases here
## "checkout fzf" checkout with fzf
cof = "!checkout_fzf() { git branch | fzf | xargs git checkout; }; checkout_fzf"
## "add fzf" add multiple files with fzf
aaf = "!add_fzf() { git status -s | awk '{print $2}' | fzf -m | xargs git add; }; add_fzf"
## "add files and commit" add files with fzf and then immediately commit
afc = "!add_files_and_commit() { git status -s | awk '{print $2}' | fzf -m | xargs git add && git commit --verbose; }; add_files_and_commit"
@gidgid
gidgid / bash
Last active October 13, 2019 14:20
Show how to use git checkout by regex
# imagine you're on master
# and you want to checkout to branch some-very-long-branch-name
$ g cor long
# using a unique part of the branch name makes it much easier to checkout
@gidgid
gidgid / .gitconfig
Last active October 17, 2020 12:48
All Git aliases in one gist
[alias]
# Adding files
## "add untracked" - no untracked files
au = add -u
## "add all" - add everything. https://stackoverflow.com/questions/572549/difference-between-git-add-a-and-git-add
aa = add -A
## "add patch" - choose what to add
ap = add -p
## "add fzf" add multiple files with fzf
aaf = "!add_fzf() { git status -s | awk '{print $2}' | fzf -m | xargs git add; }; add_fzf"
@gidgid
gidgid / .vimrc
Created March 31, 2020 19:06
Add preview to GFiles & Files in FZF.vim
" Add preview to files search
command! -bang GFiles call fzf#vim#gitfiles('', fzf#vim#with_preview('right'))
command! -bang Files call fzf#vim#files('', fzf#vim#with_preview('right'))
" Just use :GFiles & :Files regularly
@gidgid
gidgid / .vimrc
Created March 31, 2020 19:12
Add preview to Ag with FZF.vim
command! -bang -nargs=* Ag call fzf#vim#ag(<q-args>, '--color-path "1;36"', fzf#vim#with_preview(), <bang>0)
@gidgid
gidgid / .gitconfig
Created March 31, 2020 19:25
A handful of FZF Git aliases
# Navigate to branches using FZF
cof = "!checkout_fzf() { git branch | fzf | xargs git checkout; }; checkout_fzf"
# Add files using FZF
af = "!add_fzf() { git status -s | awk '{print $2}' | fzf -m | xargs git add; }; add_fzf"
# Add files using FZF and immediately commit them
afmend = "!add_fzf_amend() { git status -s | awk '{print $2}' | fzf -m | xargs git add && git amend; }; add_fzf_amend"
# Restore files (like removing multiple files from the staging area)
ref = "!restore_fzf() { git status -s | awk '{print $2}' | fzf -m | xargs git restore; }; restore_fzf"
# Delete untracked files using FZF
rmf = "!delete_untracked() { git ls-files --exclude-standard --other | fzf -m | xargs rm; }; delete_untracked"