Last active
November 27, 2023 10:33
-
-
Save renelink/2943682e2f6962e55c029b981e8e9ed1 to your computer and use it in GitHub Desktop.
Collection of useful Git aliases for windows
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Run to install: curl -s https://gist.githubusercontent.com/renelink/2943682e2f6962e55c029b981e8e9ed1/raw/git_alias_collection_win.sh | bash | |
# !!!! RUN THIS SCRIPT IN CYGWIN OR WIN GIT BASH ONLY !!!! | |
# | |
# This script uses windows paths that will only work in cygwin or the windows git bash | |
# add git np alias if notepad++ exists | |
if [ -f "C:\Program Files\Notepad++\notepad++.exe" ]; then | |
# COMMAND: git np <GIT_COMMAND> | |
# This alias is useful when you only want to use notepad++ in some situations and usually want to use the default editor. e.g. vim | |
# | |
# USAGE: | |
# git np commit | |
# git np config -e | |
# git np rebase -i origin/main | |
git config --global alias.np '!sh -c '"'"'export GIT_EDITOR="'"'"\'C:\\\\\\Program\\\ Files\\\\\\Notepad++\\\\\\notepad++.exe\'"'"' -multiInst -notabbar -nosession -noPlugin" && git $*'"'"' @*' | |
fi | |
# COMMAND: git hs <GIT_LOG_ARGS> | |
# print a colored oneline history with timestamp and history tree. | |
# | |
git config --global alias.hs "log --pretty='%C(yellow)%h %C(cyan)%cD %Cblue%aN%C(auto)%d %Creset%s' --graph --date=relative --date-order" | |
# COMMAND: git ll <GIT_LOG_ARGS> | |
# print oneline history with author and timestamp. | |
# | |
git config --global alias.ll "log --pretty=format:'%C(yellow)%h %Cred%ad %Cblue%an%Cgreen%d %Creset%s' --date=short" | |
# COMMAND: git cl <GIT_COMMIT_ARGS> | |
# commit using the last commits message. | |
git config --global alias.cl "commit -c HEAD --reset-author" | |
# COMMAND: git reflist | |
# List refs and basic info like commitid commit message author and date. | |
git config --global alias.reflist '!f() { git for-each-ref refs/ --format='"'%(HEAD) %(color:red)%(objectname:short)%(color:reset) - %(color:yellow)%(refname:short)%(color:reset) - %(contents:subject) - %(authorname) (%(color:green)%(committerdate:relative)%(color:reset))'"' \"$1\" \"$2\" \"$3\" \"$4\"; }; f' | |
# COMMAND: git cb | |
# "clean branches" deletes all local branches that are not integrated in the main branch. | |
# Asks the user to continue and supports dry run. | |
git config --global alias.cb '!f() { export main_branch_name=$(git remote show origin | sed -n "/HEAD branch/s/.*: //p"); read -n 1 -p "Do you want to delete all local branches that are already integrated in the \"${main_branch_name}\" branch (y/n/d) (d=dry run)? : " delete_branches; echo ""; if [ "$delete_branches" = "y" ] || [ "$delete_branches" = "d" ]; then git for-each-ref --format="%(refname:short)" --merge=origin/${main_branch_name} refs/heads | grep -v $main_branch_name | while read -r ref; do if [ "$delete_branches" = "d" ]; then echo "[DRY RUN]: deleting $ref"; else git branch -d $ref; fi; done; fi }; f' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment