Fixing the “protocol error: bad pack header” error in git

When trying to push in git, you might get the following error message: fatal: internal server error remote: internal server error fatal: protocol error: bad pack header In my case, it was because I pulled a corrupted remote Gerrit repository, and tried to push the corrupted data back to the fixed remote. Everyone who had […]

Deleting directories while preserving symlinks

At work, we needed to replace a pre-existing folder with a symlink. We wanted to symlink the user’s .git/hooks folder to ../build/git-hooks every time the script was run. We wanted to delete .git/hooks if it existed and replace it with a symlink, but we also wanted to avoid deleting ../build/git-hooks‘s contents by accident if the […]

Multiple git stashes

Did you know git can keep multiple stashes? If you use git stash and git stash apply, you might be tempted to think there is a single stash, but you can restore older stashes, and thus stash multiple items. To see your previous stashes, use git stash list. You will get a result like this: […]

Add some color to the OSX Terminal

If you find the OS X Terminal’s lack of color hard on the eyes, here’s how to set the colors. To get this color scheme, open ~/.bash_profile and add this: export CLICOLOR=1 export LSCOLORS=GxFxCxDxBxegedabagaced export PS1=”\[\033[36m\]\u\[\033[m\]\[\033[32m\]:\[\033[33;1m\]\W\[\033[m\]\$ ” alias ls=’ls -GFh’ The first line enables colors, the second sets the colors for ls and the last […]

OS X Terminal: Open the current folder in Finder

If you use the OS X terminal, you are probably familiar with the open command. Essentially, it opens the given file with the default application, or with the application specified with the -a parameter. For example, open hello.txt will open hello.txt using TextEdit or your default text editor. You can also use this command to […]

Linux tip: repeat a command as sudo

When you run a command in the terminal, and realize it requires superuser permissions, use the following command to re-run the command as superuser: sudo !! Here is an example scenario: apt-get install myapplication (permission denied) sudo !! The best part is that you can use this to prefix your command with anything. In the […]

OS X: Get a voice notification when commands finish running

If you are like me, you might get distracted while waiting for your unit tests to complete, and only return to your IDE several minutes later. On OS X, there is a nifty say command that makes your Mac say anything you want using text-to-speech. By appending it at the end of a long-running command, […]

How to show grep results results in context

If you are using grep, you might want to give your results a little context and see lines before and after. The -C argument lets you specify the number of lines to show before and after the result. For instance, grep my_string my_file.txt -C 2 will show two lines before and two lines after your […]

How to run Django in a command line terminal

Let’s say, for example, that you want to manually add certain objects without using the admin, or need to quickly check a function without creating unit tests for it. In that case, you will need to run Django-specific commands from a python shell. If you import django or use shell, you will probably hit […]