Skip to content

Instantly share code, notes, and snippets.

@hughsaunders
Created July 12, 2017 09:12
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 hughsaunders/ec3b65a230dbd47e8020ec2921df0d5e to your computer and use it in GitHub Desktop.
Save hughsaunders/ec3b65a230dbd47e8020ec2921df0d5e to your computer and use it in GitHub Desktop.
# git push force set upstream
gpfsu(){
branch=$(git symbolic-ref --short HEAD)
git push -f --set-upstream ${1:-origin} $branch
}
# git commit ammend
gca(){
#don't want to commit accidental submodule sha changes (eg when switching branches)
git submodule update
# store old head
oh=$(git rev-parse HEAD)
git commit -a --amend --no-edit \
&& git --no-pager diff HEAD@{1} \
&& echo "$oh --> $(git rev-parse HEAD)"
}
# git push force
gpf(){
git push -f $1 || gpfsu ${1:-origin}
}
# git branch contains file
gbcf(){
regex="${1}"
remote="${2:-origin}"
git fetch "$remote"
for branch in $(git for-each-ref --format="%(refname)" refs/remotes/$remote/*)
do echo $branch
git ls-tree -r --name-only $branch | grep "$regex"
done
}
# git commit ammend push force
alias gcapf='gca && gpf'
# git remote add hugh
alias grah='git remote add hugh git@github.com:hughsaunders/$(basename $PWD); git remote -v'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment