Skip to content

Instantly share code, notes, and snippets.



Last active Aug 29, 2015
What would you like to do?
finding stuff

##find ignored files in directory

git clean -n -X

##... delete them

git clean -X

##changes made in staged (in-index-but-not-commited) files

git diff --staged

#checkout multiple git repos from github

repos=(repo1 repo2 repo3)

for i in "${repos[@]}"
    if [ -d "$i" ] 
        echo "Directory $i exists. Not fetching."
        echo "Fetching $i ..."
        git clone<yourusername>
        echo "Fetching $i ... Done"

#save work before rebasing from master

You want to pull from master and replay your changes on top of that. But you have unstaged changes in working directory. Do the following :

git stash
git pull --rebase
git stash pop

#remove unwanted folders from git repo

#This script will help you remove unwanted folders in your git repository along with the associated history


#all the paths you want to retain in the repo

mkdir $TARGET

cp -R $SRC/.git ./$TARGET/.git

cd $TARGET  

git reset --hard HEAD

echo "pulling all remote branches.."
git branch -r  | cut -d "/" -f2,3 | grep -v HEAD | xargs -n 1 git checkout

git remote rm origin

git checkout master

echo "rewriting history.."
git filter-branch --index-filter "git ls-files | grep -E -v '$INCLUDE_PATHS' | tr '\n' ' ' | xargs git rm --cached --ignore-unmatch" --prune-empty --tag-name-filter cat -- --all

echo "deleting unused backup references.." 
git for-each-ref --format="%(refname)" refs/original/ | xargs -n 1 git update-ref -d

git reflog expire --expire=now --all

git reset --hard

echo "garbage collecting unwanted objects.."
git gc --aggressive --prune=now

echo "done!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.