Skip to content

Instantly share code, notes, and snippets.

@nikostoulas
Last active January 23, 2023 08:57
Show Gist options
  • Save nikostoulas/85eb028dc7c7f281fb84cd81bedfb071 to your computer and use it in GitHub Desktop.
Save nikostoulas/85eb028dc7c7f281fb84cd81bedfb071 to your computer and use it in GitHub Desktop.
Github aliases
# To make it easier to work on a anti git flow branching model described here: http://endoflineblog.com/gitflow-considered-harmful
# the following aliases have been created
[alias]
lg = log --graph --pretty=format:'%Cred%h%Creset [%C(dim cyan)%ad%Creset] %C(dim green)%an%Creset: %C(bold dim white)%s%Creset %C(auto)%d%Creset' --date=short
make-hotfix = !git stash && git hotfix-create $1 && git stash pop && :
graph = log --graph --color --pretty=format:'%Cred%h%Creset [%C(dim cyan)%cr%Creset] %C(dim green)%an%Creset: %C(bold dim white)%s%Creset %C(auto)%d%Creset'
tree = log --all --graph --decorate=short --color --format=format:'%C(bold blue)%h%C(reset) %C(auto)%d%C(reset)\n %C(dim cyan)[%cr]%C(reset) %x09%C(dim cyan)%an:%C(reset) %C(bold cyan)%s %C(reset)'
hotfix-create = "!f() {\
red=`tput setaf 1`;\
yellow=`tput setaf 3`;\
reset=`tput sgr0`;\
run() {\
echo "${yellow}-\\> $@ ...${reset}";\
eval $@;\
return $?;\
};\
if [ -z "$1" ]; then echo "No branch name given"; exit 1; fi;\
run git fetch origin --tags --prune;\
run git checkout -b $1 `git rev-list --tags --max-count=1`;\
}; f"
hotfix-close = "!f() {\
red=`tput setaf 1`;\
yellow=`tput setaf 3`;\
reset=`tput sgr0`;\
run() {\
echo "${yellow}-\\> $@ ...${reset}";\
eval $@;\
return $?;\
};\
if [ -z "$1" ]; then echo "No branch name given"; exit 1; fi;\
if [ -z "$2" ]; then echo "No tag version given"; exit 1; fi;\
run git fetch origin --tags --prune;\
run git checkout $1;\
run git rebase `git rev-list --tags --max-count=1`;\
if [ $? -ne 0 ]; then\
echo "${red} Rebase to latest tag failed, aborting. Please fix rebase manually and try again."; \
exit 1;\
fi;\
run git tag $2;\
run git checkout master;\
run git pull;\
run git merge $1;\
if [ $? -ne 0 ]; then\
echo "${red} Merge with master failed, aborting. Please fix merge manually and do the following: ${reset}";\
echo "Please run ${yellow} git push origin refs/heads/$1:refs/heads/$1 -f ${reset}";\
echo "Please run ${yellow} git push-all ${reset}";\
echo "Please run ${yellow} git delete-branch $1 ${reset}";\
exit 1;\
fi;\
if [[ $3 == "-f" ]]; then\
run git push origin refs/heads/$1:refs/heads/$1 -f;\
run git push-all;\
run git delete-branch $1;\
else \
echo "Please run ${red} git push origin refs/heads/$1:refs/heads/$1 -f ${reset}";\
echo "Please run ${red} git push-all ${reset}";\
echo "Please run ${red} git delete-branch $1 ${reset}";\
echo "You could have run with -f as third param to automatically run the above.";\
fi;\
}; f"
delete-tag = !git tag -d $1 && git push origin :refs/tags/$1 && :
feature-create = "!f() {\
red=`tput setaf 1`;\
yellow=`tput setaf 3`;\
reset=`tput sgr0`;\
run() {\
echo "${yellow}-\\> $@ ...${reset}";\
eval $@;\
return $?;\
};\
if [ -z "$1" ]; then echo "No branch name given"; exit 1; fi;\
run git fetch origin --tags --prune;\
run git checkout master && run git pull && run git checkout -b $1;\
}; f"
feature-close = "!f() {\
red=`tput setaf 1`;\
yellow=`tput setaf 3`;\
reset=`tput sgr0`;\
run() {\
echo "${yellow}-\\> $@ ...${reset}";\
eval $@;\
return $?;\
};\
red=`tput setaf 1`;\
yellow=`tput setaf 3`;\
reset=`tput sgr0`;\
if [ -z "$1" ]; then echo "No branch name given"; exit 1; fi;\
run git fetch origin --tags --prune;\
run git checkout $1;\
run git rebase origin/master;\
if [ $? -ne 0 ]; then\
echo "${red} Rebase to master failed, aborting. Please fix rebase manually and try again."; \
exit 1;\
fi;\
run git checkout master;\
run git pull;\
run git merge $1;\
if [ $? -ne 0 ]; then\
echo "${red} Merge with master failed, aborting. Please fix merge manually and do the following: ${reset}";\
echo "Please run ${yellow} git push origin refs/heads/$1:refs/heads/$1 -f ${reset}";\
echo "Please run ${yellow} git push-all ${reset}";\
echo "Please run ${yellow} git delete-branch $1 ${reset}";\
exit 1;\
fi;\
if [[ $2 == "-f" ]]; then\
run git push origin refs/heads/$1:refs/heads/$1 -f;\
run git push-all;\
run git delete-branch $1;\
else \
echo "Please run ${red} git push origin refs/heads/$1:refs/heads/$1 -f ${reset}";\
echo "Please run ${red} git push-all ${reset}";\
echo "Please run ${red} git delete-branch $1 ${reset}";\
echo "You could have run with -f as second param to automatically run the above.";\
fi;\
}; f"
push-all = !git push --tags && git push
delete-branch = !git branch -d $1 && git push origin :refs/heads/$1 && :
release-create = !git feature-create $1
release-close = "!f() {\
red=`tput setaf 1`;\
yellow=`tput setaf 3`;\
reset=`tput sgr0`;\
run() {\
echo "${yellow}-\\> $@ ...${reset}";\
eval $@;\
return $?;\
};\
if [ -z "$1" ]; then echo "No branch name given"; exit 1; fi;\
if [ -z "$2" ]; then echo "No tag version given"; exit 1; fi;\
run git feature-close $1 && git tag $2;\
}; f"
@nikostoulas
Copy link
Author

  • Features and hotfixes are created locally
  • Features are made pull requests in master and closed in github
  • Hotfixes are made pull requests in master but are closed locally (so that both tag is created and a merge is done)
  • Releases are created and closed locally.
  • nodejs projects can have a simpler release creation since npm version (patch, minor, major) does the same thing.

@nikostoulas
Copy link
Author

To delete all tags not starting with number of v (for nodejs projects)
git tag -l | grep ^[^v0-9] | xargs -n 1 git delete-tag

@nikostoulas
Copy link
Author

nikostoulas commented Dec 20, 2016

Find latest tag

git describe  `git rev-list --tags --max-count=1`

@SokratisVidros
Copy link

git graph = log --color --graph --pretty=format:"%h | %ad | %an | %s%d" --date=short

@nikostoulas
Copy link
Author

nikostoulas commented Jan 2, 2017

The accepted values are two of normal , black , red , green , yellow , blue , magenta , cyan and white and optionally one of bold , dim , ul , blink and reverse . from https://nathanhoad.net/how-to-colours-in-git

@nikostoulas
Copy link
Author

Push specific tag to remote: git push {remote} v1.0.0^{}:master

@nikostoulas
Copy link
Author

nikostoulas commented Mar 28, 2017

To easily add the gist to your .gitconfig delete the alias part of your gitconfig and run:

curl https://gist.githubusercontent.com/nikostoulas/85eb028dc7c7f281fb84cd81bedfb071/raw/82c6e106e63fae5b7c2c5c6d94cf4482c0805769/.gitconfig |tail -n +2 >> ~/.gitconfig

@nikostoulas
Copy link
Author

nikostoulas commented May 25, 2017

Clean all branches merged in master:
git branch --merged | grep -v master |xargs git branch -d
Clean all branches not in remote:
git fetch -p && for branch in `git branch -vv | grep ': gone]' | awk '{print $1}'`; do git branch -D $branch; done

@alkiskal
Copy link

@nikostoulas
Copy link
Author

Remove tags not in remote
git tag -l | xargs git tag -d && git fetch -t

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment