Discarding Files

Remove pesky .DS_Store on Mac

find . -name .DS_Store -print0 | xargs -0 git rm -f --ignore-unmatch

Then add .DS_Store to .gitignore.

Remove files from .gitignore

Add the file to .gitignore then in the top level of the repo:

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

Discarding Changes

Discard all unstaged files

git checkout -- .

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

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

– Source: Stack Overflow


See the difference between 2 branches

git diff --name-status master..<branch>


Apply a patch from a url

For the lazy among us…

curl <url.patch> | git apply -
git commit -am "..."


Download and track remote branch

git checkout -t origin/<branch-name>

Push branch to live and track it

git checkout -b <branch-name>
git push -u origin <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.


Use a different SSH Key for a different server

Inside ~/.ssh/config put:

Host github.com
  HostName github.com
  User git
  PreferredAuthentications publickey
  IdentityFile ~/.ssh/different_rsa

Use your SSH Keys inside a VM

host <ip-address-of-vm>
  ForwardAgent yes

Make Git use your text editor instead of Vim

~ git config --global core.editor "atom --wait"~

Replace atom --wait with your text editor. See list of options.

File System Issues

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

chmod g+w <directory>

Fix “modified files” issue after clone

This is git seeing differences in line endings on your file system. In ~/.gitattributes add:


– Source: Stack Overflow

Kickstarter Coming January

I'm launching a board game called Delivery Duck. You're a duck, in a truck, delivering packages. It's a strategic family game for 2 to 6 players.

Check out the board game!