Skip to content

Instantly share code, notes, and snippets.

@michaelkarrer81
Last active January 31, 2019 20:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save michaelkarrer81/cb8a7f744feffb627188 to your computer and use it in GitHub Desktop.
Save michaelkarrer81/cb8a7f744feffb627188 to your computer and use it in GitHub Desktop.
[GIT Installation and Configuration] Git installation and configuration options #git
#!/usr/bin/env bash
# https://medium.com/@porteneuve/mastering-git-submodules-34c65e940407#.3o6drt47o
# http://blogs.atlassian.com/2013/03/git-submodules-workflows-tips/#scenarios
# http://stackoverflow.com/questions/2144406/git-shallow-submodules
# -----------------
# INSTALL AND SETUP
# -----------------
# https://github.com/bobthecow/git-flow-completion/wiki/Install-Bash-git-completion
brew install git && brew install bash-completion
# Add bash-completion to your ~/.bash_profile
# ~/.bash_profile START ---------------
export ARCHFLAGS='-arch i386 -arch x86_64'
export PATH=$PATH:/Applications/Postgres.app/Contents/Versions/9.3/bin
export ANDROID_HOME=/usr/local/opt/android-sdk
alias ll='ls -lahG'
export PATH="/usr/local/bin/git:/usr/local/bin:/usr/local/sbin:$PATH"
#
# Bash completion
if [ -f $(brew --prefix)/usr/local/etc/bash_completion ]; then
. $(brew --prefix)/usr/local/etc/bash_completion
fi
#
# git bash info
# make sure git_completion is located at /usr/local/etc/bash_compleation.d/
source /usr/local/etc/bash_completion.d/git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=true
export PS1='[\u@mbp \w$(__git_ps1)]\$ '
# ~/.bash_profile END ---------------
# Show all Branches with remote information
git branch -avv
# Remove all local branches that are already merged into the remote
#git branch -D $(git branch --merged) # will only work if the current checkout branch is master
#http://stevenharman.net/git-clean-delete-already-merged-branches
git branch --merged master | grep -v "\* master" | xargs -n 1 git branch -d
git remote prune origin
# Reset one file
git checkout -- [PATH_TO_FILE/FILENAME]
# ----------
# Submodules
# ----------
# Get shallow copies
git clone --recurse-submodules --shallow-submodules
# Avoid shallow copies e.g. for dev work
git clone --recurse-submodules --no-shallow-submodules
# It is possible to automate submodules pushes further with:
# http://stackoverflow.com/questions/14768509/unable-to-checkout-git-submodule-path
git push --recurse-submodules=on-demand
#which also pushes submodules as needed, or starting with 2.7:
git config push.recurseSubmodules on-demand
git push
# https://medium.com/@porteneuve/mastering-git-submodules-34c65e940407#.3o6drt47o
git config --global status.submoduleSummary true
# ---
# clean and reset repo
# ---
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment