Skip to content

Instantly share code, notes, and snippets.

@andrewvaughan
Created April 27, 2019 01:28
Show Gist options
  • Save andrewvaughan/3a91818bcd61fb8062e5df1d7b732be5 to your computer and use it in GitHub Desktop.
Save andrewvaughan/3a91818bcd61fb8062e5df1d7b732be5 to your computer and use it in GitHub Desktop.
A collection of git aliases for `.bash_profile`
#### SPECIAL GIT SHORTCUTS (Andrew Vaughan <[email protected]>)
#
# Checkout a git branch - creates and pushes it if it doesn't exist
#
branch() {
local branch="$1"
if [ -z "$branch" ]; then
echo
echo "usage: branch branch-name"
echo ""
echo "This command will create a branch if it does not exist and push it to the origin"
echo "remote. If the branch exists, it will simply checkout the branch."
echo
return
fi
# Attempt to checkout an existing branch, exiting if successful
git checkout $branch && return
echo
echo "Branch '${branch}' does not exist... attempting to create..."
if [[ $branch != *"/"* ]]; then
echo
echo "Error: '$branch' is not a valid branch for Git Flow; it follow the format like 'feature/branch-name' or any of the following:"
echo
echo " bugfix/ - the repair of a known bug"
echo " document/ - documentation updates"
echo " feature/ - a new or updated feature"
echo " hotfix/ - a hotfix for urgent release"
echo " maint/ - a maintenance or devops update"
echo " release/ - a version release"
echo
return
fi
echo
git checkout -b $branch
git push -u origin $branch
echo
}
alias ip='dig +short myip.opendns.com @resolver1.opendns.com' # Shows your public IP address
alias ls='ls -GFh' # Makes `ls` command easier to read
alias ll='ls -GFhal' # Displays files as a list
alias egrep='egrep --color=always' # Ensures greps are always colored
alias grep='egrep' # Uses regex for all grep commands
alias g='git' # Shorthand for `git`
#alias branch='g branch' # Checks out or creates a branch
alias gl='g log --pretty=format:"%C(yellow)%h\\ %ad%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate --date=short'
alias gl1='g log --oneline --decorate --all'
alias ga='g add -A' # Stages all files for commit
alias gc='g commit -m' # Commits all staged files
alias gac='ga && gc' # ga and gc commits combined
alias gpp='g pull && g push' # Pulls and pushes!
alias gamend='g commit --amend --verbose' # Amend the last commit message
alias gd='g diff' # Show a diff of un-added files
alias gdc='gd --cached' # Show a diff of added files
alias gs='g status' # Show status of git folder
alias gco='g checkout' # Shorthand to checkout a branch or tag
alias rmbranch='g branch -d' # Removes a branch
alias rebase='git fetch --all && git fetch --tags && git pull && git rebase upstream/develop' # Rebases from upstream/develop
alias shortcuts='GREP_COLOR="01;32" egrep "^#?alias" ~/.bash_profile | GREP_COLOR="01;34" egrep " .*" | GREP_COLOR="01;35" egrep "=" | GREP_COLOR="01;37" egrep "#.*$" | egrep -v "shortcuts"'
#### END SPECIAL GIT SHORTCUTS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment