Last Updated: February 25, 2016
·
418
· hvasconcelos

Git Interactive Staging in shell script

Clone the script from github gist for you enviroment

Example:

mkdir ~/bin/
cd /bin
curl https://gist.github.com/hvasconcelos/6081058/raw/d071cf06dddace0178d92f32af59b74038e4bff4/gitistage > gitistage
chmod u+x gitistage
export PATH=$PATH:~/bin/

Code

#!/bin/bash
files=`git status --porcelain  | grep -e "^\sM" | cut -d " " -f 3`
for file in $files; do 
    echo "Differences in file"
    git diff --color=always $file
    read -p "Do you want to stage this file [y/n]" to_stage
     if [ "$to_stage" == "y" -o "$to_stage" == "Y" ];  then
        echo "Staging file -> $file" 
        git add $file
    fi
done