Skip to content

Instantly share code, notes, and snippets.

@Swivelgames
Last active February 12, 2019 22:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Swivelgames/a1c0ff1231f5fdbe4dafade84aae8f5a to your computer and use it in GitHub Desktop.
Save Swivelgames/a1c0ff1231f5fdbe4dafade84aae8f5a to your computer and use it in GitHub Desktop.
Useful Git Aliases
# ...
[pull]
# Use rebase when running git-pull (Recommended)
rebase = true
[core]
# Treat filename casing strictly
ignorecase = false
[pager]
# Do not open up the default kernel's pager for git-branch
branch = false
[alias]
# List only the MY local and remote branches
mine = "!f() { git branch -a | grep --color=always '\\(^[^\\/]*$\\)\\|origin'; }; f"
# Usage: git update-using BRANCH_NAME
# Useful when working within a fork to sync your fork with upstream changes
# 1. Saves name of current branch
# 2. Checks out BRANCH_NAME
# 3. Pulls BRANCH_NAME from 'upstream'
# 4. Force pushes BRANCH_NAME to 'origin'
# 5. Checkouts out last branch and rebases BRANCH_NAME ontop
update-using = "!f(){ \
CUR_BRANCH=$(\
git rev-parse --abbrev-ref HEAD\
); \
git fetch --all --prune && \
git checkout "$1" && \
git pull upstream "$1" && \
git push --force --no-verify origin "$1":"$1" && \
git checkout $CUR_BRANCH && \
git rebase "$1"; \
}; f"
# **DESTRUCTIVE**
# Usage: git prune-merged BRANCH_NAME
# Lists all branches that have been merged into BRANCH_NAME
# and asks the user if they want to delete them.
# If yes, the script proceeds to delete both local and origin
# remote versions of the branch.
prune-merged = "!f(){ git fetch --all --prune; \
BRANCHES=$(\
git branch --merged "$1" | egrep -v '(^\\*|REL_*|master|develop)'\
); \
echo 'PRUNING:'; \
echo $BRANCHES; \
echo 'Are you sure you want to delete these branches?'; \
read voidvar; \
for B in $BRANCHES; \
do git push --no-verify origin :$B; \
done; \
git branch -d $BRANCHES; \
}; f"
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment