Discarding Files

Removing pesky .DS_Store on Mac
find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch
Then add .DS_Store to .gitignore.

Discarding Changes

Remove files from .gitignore

git rm -r --cached .
git add .
git commit -m "fixed untracked files"


git rm --cached <filename>
git rm -r --cached <folder>

Discard all unstaged files
git checkout -- .
or git reset --hard
git clean -nd (dry run) git clean -fd (-f is force, -d is remove directories)

Revert a file
git checkout -- <filename>
or get file from origin git checkout origin/master -- <filename>

Reset local to origin http://stackoverflow.com/a/8888015

git fetch --all
git reset --hard origin/master


See the difference between 2 branches
git diff --name-status master..<branch>


Applying a patch

curl <url.patch> | git apply -
git commit -am "..."
git push -u origin 7.x-2.x

Download and track remote branch

git checkout -t origin/branch-name

Push branch to live and track it

git checkout -b feature_branch_name
git push -u origin feature_branch_name


Merge master into your branch:

git checkout <branch>
git merge master

If it pops you into vim then press esc to return to command mode and enter ZZ to save and exit (and commit). You can input text with i. And :wq just quits.

File System Issues

Unable to unlink old directory (Permission denied)
If you get “error: unable to unlink old ‘' (Permission denied)". On the parent directory do:

chmod g+w <directory>

Fix modified files straight after clone http://stackoverflow.com/a/10363472 Add "text=auto" in ~/.gitattributes

I'm launching a board game. If you'd like to know when it launches feel free to signup to my mailing list:

Mailing List

I hate spam just as much as you do and will probably never send an email out because I consider myself spam.