Wednesday, November 18, 2015

Easy Bash Git Scripts

While enjoying all the benefits of git source control on my local development machine I thought I would share a few of my favorite shortcut scripts I've created for you to enjoy.

This script is used to display the stat diff version between master and the current branch I'm working on. Save the script below in an executable path named gitstat.

echo ""
echo "Command: git diff --stat master..$1"
echo "----------------------------------------------------"
git diff --stat master..$1
echo ""

Run it with the command: gitstat branch_name

This is a simple echo of commonly used command line options for git to give me a quick reminder when I may forget something. Save the script in a executable path and name it githelp.

echo "Useful git commands"
echo "---------------------------------------------------------------------------"
echo "Create Branch              :   git branch nameofbranch"
echo "Switch to Branch           :   git checkout nameofbranch" 
echo "Update master              :   git checkout master | git merge nameofbranch"
echo "Remove branch              :   git branch -D nameofbranch"
echo "Add all files to staging   :   git add -all"
echo "Add staged files to branch :   git commit -m \"message\""
echo "Show diff between branches :   git diff branchone..branchtwo"
echo "Show all branches          :   git branch"

echo ""

Run it with the command: githelp

No comments:

Post a Comment