Last active
August 29, 2024 09:57
-
-
Save fdv/b960b2b83df1fd0b6559311336d7a5bb to your computer and use it in GitHub Desktop.
A few useful git commands
This file contains hidden or 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
# in /usr/local/bin/git-cleanup-merged | |
#!/bin/sh | |
#!/usr/bin/env bash | |
current_branch=$(git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/') | |
if [ "$current_branch" != "master" ] && [ "$current_branch" != "main" ]; then | |
echo "WARNING: You are on branch $current_branch, NOT master or main." | |
fi | |
echo "Fetching merged branches..." | |
git remote prune origin | |
remote_branches=$(git branch -r --merged | grep -v '/master$' | grep -v '/main$' | grep -v "/$current_branch$") | |
local_branches=$(git branch --merged | grep -v 'master$' | grep -v '/main$' | grep -v "$current_branch$") | |
if [ -z "$remote_branches" ] && [ -z "$local_branches" ]; then | |
echo "No existing branches have been merged into $current_branch." | |
else | |
echo "This will remove the following branches:" | |
if [ -n "$remote_branches" ]; then | |
echo "$remote_branches" | |
fi | |
if [ -n "$local_branches" ]; then | |
echo "$local_branches" | |
fi | |
git push origin `git branch -r --merged | grep -v '/master$' | grep -v '/main$' | grep -v "/$current_branch$" | sed 's/origin\//:/g' | tr -d '\n'` | |
git branch -d `git branch --merged | grep -v 'master$' | grep -v 'main$' | grep -v "$current_branch$" | sed 's/origin\///g' | tr -d '\n'` | |
fi | |
# in /usr/local/bin/git-feature | |
#!/bin/sh | |
git checkout -b feature/${1} | |
# in /usr/local/bin/git-bug | |
#!/bin/sh | |
git checkout -b bug/${1} | |
# in /usr/local/bin/git-yolo | |
#!/bin/sh | |
git checkout master | |
for branch in $(git branch | grep -v master); do | |
git merge ${branch} | |
git push -f origin master | |
done | |
# some cool aliases | |
alias.tree log --oneline --graph --decorate | |
alias.aliases config --get-regexp alias | |
alias.commend commit --amend --no-edit | |
alias.please push --force-with-lease | |
alias.praise blame | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment