Skip to content

Instantly share code, notes, and snippets.

@Sanix-Darker
Last active May 4, 2023 16:44
Show Gist options
  • Save Sanix-Darker/a17cce1f23e488cd63223d70ab546653 to your computer and use it in GitHub Desktop.
Save Sanix-Darker/a17cce1f23e488cd63223d70ab546653 to your computer and use it in GitHub Desktop.
gitconfig stat add-intent squash
[user]
email = s4nixd@gmail.com
name = sanix-darker
[filter "lfs"]
clean = git-lfs clean -- %f
smudge = git-lfs smudge -- %f
process = git-lfs filter-process
required = true
[core]
pager = delta
editor = nvim
[interactive]
diffFilter = delta --color-only --features=interactive
[delta]
navigate = true
line-numbers = true
features = decorations
light = false
[alias]
; To use pr
; pr auth login to authenticate it !
; You can use ssh or https, but; it's better to use ssh one
; to create a new PR
pr = !EDITOR=nvim gh pr create
; to list all available pull requests
pr-list = !gh pr list
; to list all available pull requests
; Ex: git pr-view 23
pr-view = !gh pr view
; for release tags
; Interactively create a release
; $ gh release create
; Interactively create a release from specific tag
; $ gh release create v1.2.3
; Non-interactively create a release
; $ gh release create v1.2.3 --notes "bugfix release"
; Use automatically generated release notes
; $ gh release create v1.2.3 --generate-notes
; Use release notes from a file
; $ gh release create v1.2.3 -F changelog.md
; Upload all tarballs in a directory as release assets
; $ gh release create v1.2.3 ./dist/*.tgz
; Upload a release asset with a display label
; $ gh release create v1.2.3 '/path/to/asset.zip#My display label'
; Create a release and start a discussion
; $ gh release create v1.2.3 --discussion-category "General"
release = !EDITOR=nvim gh release create
; to list commits from the current branch
commit-list = !git log --no-merges --oneline --decorate $(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5)..$(git branch --show-current)
; to create a new Issur
issue = !EDITOR=nvim gh issue create
; to list all vailable issues
issue-list = !gh issue list
; to view an Issue
; Ex: git issue-view 23
issue-view = !gh issue view
; to view an Issue
issue-comment = !EDITOR=nvim gh issue comment -e
; All my commits should be signed
; git config --global commit.gpgsign true
; commit-signed = !git commit -S
; To clone a sub directory from a random project
; git clone-sub directory1 https://github.com/author/repo
; Or from a specific branch
; git clone-sub directory1 https://github.com/author/repo
clone-sub = !bash -i -c '_git_clone_sub "$@"' -s
; to cat inside a code state for a given line, commit and file as parameter
; ideal to run just after the git search
open-code = !bash -c 'source $HOME/.bash_aliases && _git_open_code "$@"' -s
; To commit an empty commit
commit-empty = !git commit --allow-empty -m \"xxx: an empty-commit\"
; only in a middle of a rebase
; git add-their
; accept incomming changes
add-their = !git checkout --ours "$@" && git add "$@"
; git add-our
; accept only current changes
add-our = !git checkout --theirs "$@" && git add "$@"
; to generate a new patch from changes
; git patch-put -1 <sha>
; git patch-put -1 HEAD
patch-put = !git format-patch $@
; to get a new patch from file
; git patch-get file.patch
patch-get = !git am < $@
; to get remote coworker's code
pull-coworker = !bash -c 'source $HOME/.bash_aliases && _git_coworker "$1"' -s
; git fork-set-upstream <git-repo-link>
fork-set-upstream = !git remote add upstream
; git refresh-fork
fork-pull-upstream = !git fetch upstream && git rebase upstream/$(git branch --show-current) && git push origin $(git branch --show-current)
; to push the current branch as an upstream
pushit = !git push --set-upstream origin $(git branch --show-current)
; To erase a file across your git history
erase = !git filter-branch --index-filter 'git rm -rf --cached --ignore-unmatch $1' HEAD
; To list all Aliasses
alias = !git config --get-regexp alias
; to undo a precedent commit you made
undo = reset HEAD~1 --mixed
; to get branch list with a lot of informations on it
branch-details = !git branch --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(contents:subject) %(color:green)(%(committerdate:relative)) [%(authorname)]' --sort=-committerdate
; To search inside commit
; And then git show to see all changes from a commit
search = !git rev-list --all | xargs git grep -F
; get diff with the vimdiff tool
vdiff = !git difftool -t vimdiff -y
; to get the last commit
last = !git log -1 HEAD --stat
; grv is a TUI to browse the git project
browser = !grv
; to get logs as oneline only
log-line = !git log --graph --pretty=format:\"%C(magenta)%h%Creset -%C(red)%d%Creset %s %C(dim green)(%cr) [%an]\" --abbrev-commit -30
; git log but with short informations
log-short = shortlog -sn --no-merges
; Same as above, but with a diff stat instead of just names
; (better for interactive use)
stat = !git diff --stat $(git merge-base HEAD $(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5))
; which adds a zero-length blob to the index at that location.
; The upshot is that your "untracked" file now becomes a modification to add
; all the content to this zero-length file, and that shows up in the "git diff" output.
add-intent = !git add -N
; The famous squash and merge for all commits on my current branch
; To a target branch
; git squash (it will target master)
; git squash dev (it will target dev branch)
squash = !git rebase -i HEAD~$(git rev-list --count HEAD ^$(git remote show origin | grep 'HEAD branch' | cut -d' ' -f5))
[merge]
conflictstyle = diff3
[diff]
colorMoved = default
[delta "interactive"]
keep-plus-minus-markers = false
[delta "decorations"]
file-style = omit
hunk-header-file-style = red
hunk-header-line-number-style = "#067a00"
hunk-header-style = file syntax
[commit]
gpgsign = true
# To clone a sub_dir
# To clone a sub directory from a random project
# _git_clone_sub directory1 https://github.com/author/repo
# Or from a specific branch
# _git_clone_sub directory1 https://github.com/author/repo
_git_clone_sub(){
REPO_NAME="$(echo $2 | grep -oE '[^/]+$')"
git init $REPO_NAME
cd $REPO_NAME
git remote add origin $2
git config core.sparsecheckout true
# Specipy the sub directory
echo "$1/*" >> .git/info/sparse-checkout
# then get it, the depth is the way too far wher you can go...
git pull origin master
}
_git_squash(){
read -p "You're about to squash all the commits from this branch ? (Y/y) " -n 1 -r
echo # (optional) move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]
then
# Commit count difference between my branch and the master branch
COMMIT_COUNT=git rev-list --count HEAD ^master
# We rebase from the amount of commit
git rebase -i HEAD~$COMMIT_COUNT
else
echo "Squash stopped"
fi
}
_git_coworker(){
remote_u=(${1//:/ })
author=${remote_u[0]}
branch=${remote_u[1]}
current_dir=$(basename $PWD)
target="git@github.com:$author/$current_dir"
echo -e "> author: $BWHITE $author $COLOROFF"
echo -e "> branch: $BWHITE $branch $COLOROFF"
echo -e "> repo-name: $BWHITE $current_dir $COLOROFF"
echo -e "> target-repo: $BWHITE $target $COLOROFF"
read -p "Those informations are good ? (Y/y): " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
git remote add $author $target
git fetch $author
git checkout --track $author/$branch
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment