Rename a git branch

I can't count the number of times that I've created a new feature branch only to notice that I've managed to add a typo to the branch name. Usually, it looks something like this:

$ git checkout -b feature/addign-login

Usually in this situation I'd create a new branch with the correct name from my current (incorrectly named) branch and delete the old one:

$ git checkout -b feature/adding-login

$ git branch -D feature/addign-login

It turns out that this happens enough for git to have an alias for it - git branch -m.

Instead of creating a new branch and deleting the old one, you can do the following:

$ git branch -m feature/adding-login

This will rename the branch that you're on in place.

[ Read More ]

Special cron entires

There are some special entries that can be used when creating a crontab entry (crontab -e), most of which are just shortcuts for the standard crontab entries that we all know and love.

You can use them in your crontab just like you would a normal entry:

# m h dom mon dow  command

# Say hello each time the machine boots up
@reboot echo 'Hello world. I just booted up'

# Say Happy new year, using both forms of entry
@yearly echo 'Happy new year'
0 0 1 1 * echo 'Happy new year from me too'

The @reboot entry could be useful for keeping track of when a machine is rebooted. Just add the crontab and each time the machine restarts you'll get an email with any output from the crontab (in this case, "Hello world. I just booted up")

Possible entries

There are nine possible aliases, some of which are just aliases for each other (such as @yearly and @annually)

Entry Description Equivalent entry
@reboot Run once, at startup None
@yearly Run once a year 0 0 1 1 *
@annually Same as @yearly 0 0 1 1 *
@monthly Run once a month 0 0 1 * *
@weekly Run once a week 0 0 * * 0
@daily Run once a day 0 0 * * *
@midnight Same as @daily 0 0 * * *
@hourly Run once an hour 0 * * * *

I'm not sure I'd recommend using any of these (except maybe @reboot) as the standard syntax is well known by anyone that should be editing a crontab, but it's interesting to know that there are aliases in there for common time periods.

(via mkaz (now offline))

[ Read More ]

git and diff-highlight

diff-highlight is a contrib script that ships with git. It's a better way to visualise a diff when the changes are small words, not entire lines/paragraphs. It's hard to explain, so here's an example (diff-highlight is the script):

[ Read More ]

git push

A nice quick tip to get the ball rolling again.

If you've ever deleted a branch on a remote system only to have it recreated when you git push, this one's for you. It will make git only push the current branch by default; other branches are not pushed to the server. This helps to ensure for example that deleted branches do not get re-pushed accidentally.

git config --global push.default current`

If you do want to push all branches you've got locally, you can use the --all flag like so:

git push --all
[ Read More ]

The Unix Toolbox

This article originally appeared in the December 2013 issue of PHP Architect

The beauty of a Unix-based operating system is that it has a multitude of useful tools that most people don't know about. You can use them on their own, chain them together, you can do almost anything you can think of.

We'll take a look at some popular tools and some lesser known gems. As well as tools, we'll cover tips and tweaks for making your command line do all the work so that you don't have to. From search and replace to installing software without having to find it first, the command line can do it all!

[ Read More ]