How to make the most current version of git available on macOS

macOS and Xcode are always a few releases behind the currently available version of git. There are just a few simple things you need to do in order to rectify this inequity. If you are reading this then you are probably already familiar with the git CLI commands, but just to be sure:

  • check the version of git
ewilson$ git version
git version 2.9.3 (Apple Git-75)
  • check to see where git is being executed from
ewilson$ which git
/usr/bin/git

If your system looks like this then you'll need to modify your .bash_profile (if you run bash - or modify the profile file for your corresponding shell). Since I am going to use homebrew for the new git install I need to make sure the path of the new executable (brew installs in /usr/local/bin) comes before the macOS version which is typically located in /usr/bin. Thusly:

export PATH=/usr/local/bin:$PATH

Now all that's left is to install git and you are golden

ewilson$ brew install git
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> New Formulae
metricbeat
==> Updated Formulae
...

==> Downloading https://homebrew.bintray.com/bottles/git-2.10.2.sierra.bottle.1.tar.
######################################################################## 100.0%
==> Pouring git-2.10.2.sierra.bottle.1.tar.gz
==> Caveats
Bash completion has been installed to:
/usr/local/etc/bash_completion.d

zsh completion has been installed to:
/usr/local/share/zsh/site-functions

Emacs Lisp files have been installed to:
/usr/local/share/emacs/site-lisp/git
==> Summary
🍺/usr/local/Cellar/git/2.10.2: 1,445 files, 31.8M

Now when you run git version you should see the latest and greatest

ewilson$ git version
git version 2.10.2

Awesome. To keep things up to date all you'll need to do is run brew upgrade

brew upgrade git

Don't forget to update any tools or IDEs that you may have been using to make sure that they now point at your shiny new version of git.

How to stop macOS Mail app from saving multiple drafts to Gmail

I was having a niggling issue when bouncing back and forth between the macOS Mail app and the web interface of Gmail. If I started composing an email in Mail I found that when I went to view the inbox via the Gmail web interface I was presented with a litany of (mostly) empty Draft messages. Annoying.

There was a simple solution which I found in Mail's Account Preferences. It is thus:

  1. Fire up Mail
  2. Go to Preferences...
  3. Select Accounts tab
  4. Select Gmail IMAP account
  5. Select Mailbox Behaviors 
  6. Uncheck "Store draft messages on the server"
  7. Save
  8. Life and your inbox are in harmony once again

The account preferences for draft messages should look like the following:

How to password protect a zip file in Mac OSX

For some reason there is no way (as of the date of this writing) to right click, zip and password protect a file in OSX. So we have to go to the Terminal app, or my preference - iTerm2.

I like to launch pretty much everything in OSX by using the shortcut/hotkey: Command + Space bar. This will open the Spotlight Search bar for you. Type “Terminal” in Spotlight, then double-click on Terminal (or select it and press the enter key) to open it. Alternatively, you can go to Finder, scroll down to “Utilities,” and then select “Terminal” from the Utilities programs folder.

In the Terminal window you'll have to navigate to the location of the file you want to zip. Once there type:

zip –e name_of_zip_file_to_create name_of_file_to_zip
  • The “-e” flag means create an encrypted zip file.
  • The first file name is what you want the zipped file to be called.
  • The second file name is the folder or file you want to zip.

Example

Erics-MBP:~ ewilson$ cd Desktop/
Erics-MBP:Desktop ewilson$ zip -e wilson.zip wilson.pdf
Enter password:
Verify password:
adding: wilson.pdf (deflated 4%)

As you can see the archive utility will ask you to enter a password twice. Complete this step and you'll have successfully password protected you zip file.

How to shut down VirtualBox / Vagrant from CLI

So you need to stop one or more running VirtualBox instances that you may have started and are hanging around. Here are a few helpful commands:

List all running machines (returns name and UUID)
VBoxManage list runningvms

Stop running VMs by "hibernating" them (recommended to avoid data loss)
VBoxManage controlvm <name|uuid> savestate

Poweroff running VMs (not recommended because we may lose data in the guest)
VBoxManage controlvm <name|uuid> poweroff

Use ACPI in an ACPI-aware guest OS (preferable to poweroff for graceful shutdown of guests)
VBoxManage controlv m <name|uuid> acpipowerbutton

How to setup / use Mac to Mac remote desktop connection

On the machine you want to remotely connect to:

  • Go to System Preferences.
  • Click on Sharing folder.
  • If necessary, click the lock at bottom left and enter your password to make changes.
  • Put a check mark next to Screen Sharing on the left.
  • OPTIONAL: Click the Computer Settings… button on the right.
  • Put a check mark next to “VNC viewers may control screen with password:” and set a password to use for screen sharing.
  • Click OK.
  • To secure logins to only your account, make sure it’s set to “Allow access for: Only these users.” Click the plus button at the bottom of the list.
  • Select your name (or the name of the user account you use) from the list and click the Select button. If you would like to enable file sharing as well, put a check mark next to File Sharing on  the left.

On the machine you’ll be connecting from:

  • Go to Finder.
  • Select Connect to Server from the Go menu.
  • In the Server Address field type in the IP address of your remote computer preceded by “vnc:”.
  • Click the Connect button and it will open the remote desktop in a new window. You will have control over the keyboard and mouse as if you were sitting down at that computer.
  • When you’re done, close that window.
  • To access files and folders on the remote computer, select Go to Folder from the Go menu.
  • Type in the IP address of the computer you wish to connect to preceded with “afp:” as it appeared in File Sharing above.
  • Click the Go button and the folders you have access to on the remote computer will open in a new Finder window.
  • When you’re done, close that window.