Environment Variables (without admin privileges) for Command Line


If you don’t have Admin rights to a machine and you need to add environment variables it can be a real pain in the neck to have to get Ops every time to do it. You can update the system PATH in a batch file, but it can be a hassle to have to source this file every time you open a command terminal. The following process allows you to automatically source any environment variables every time you open a terminal.

  1. Start the command prompt and ‘pin’ it to the taskbar.
  2. Right-click on it, edit properties, and append -cmd /K env.bat to the Target property.


%windir%\system32\cmd.exe -cmd /K env.bat

3. Create a batch file called env.bat and place it in your home folder. This file should include any environment variables you need set. For example:

@echo off

if "%ANT_HOME%"=="" (
 echo Setting environment...
) else (
 echo Environment already defined.
 exit /b

set ANT_HOME=C:\apps\apache-ant-1.9.6
set APACHE_HOME=C:\opt\apache2
set GIT_HOME=C:\Users\philip.murphy\AppData\Local\Programs\Git
set JAVA_HOME=C:\apps\jdk8u66
set JBOSS_HOME=C:\opt\jboss
set M2_HOME=C:\apps\apache-maven-3.0.3
set ONE_DRIVE="C:\Users\philip.murphy\OneDrive - Globoforce"
set ADB_PATH=C:\apps\android-sdk-windows\platform-tools
set CATALINA_HOME=C:\opt\tomcat
set ORACLE_HOME=C:\oraclexe\app\oracle\product\11.2.0\server
set TNS_ADMIN=C:\oraclexe\app\oracle\product\11.2.0\server\network\ADMIN
set FFMPEG_HOME=C:\apps\ffmpeg
set SEVEN_ZIP="C:\Program Files\7-Zip"
set CHROME_HOME="C:\Program Files (x86)\Google\Chrome\Application"
set IMAGEMAGICK=C:\apps\imagemagick

set path=%ONE_DRIVE%\bin;%ANT_HOME%\bin;%APACHE_HOME%\bin;%GIT_HOME%\bin;%GIT_HOME%\usr\bin;%GIT_HOME%\mingw64\bin;%JAVA_HOME%\bin;%M2_HOME%\bin;C:\Ruby187\bin;C:\Python27;%ADB_PATH%;%FFMPEG_HOME%\bin;%SEVEN_ZIP%;%CHROME_HOME%;c:\apps;%IMAGEMAGICK%;%path%

Set and forget – you’re done.


Deploy from Windows to Linux using SSH


I generally develop on Windows and deploy to Linux servers where our Apache and Tomcat instances are running. The following single command is a bit of magic. It does the following:

  1. Tars up all the files for mywebapp
  2. Transfers them using ssh
  3. Extracts them to the correct location and as the correct user (builduser in this example) on the deployment machine.
tar -C c:/opt/apache2/htdocs/mywebapp -cvf - . | ssh philip.murphy@my-build-server.com "sudo -u builduser tar -C /var/www/html/mywebapp -xmf -"

GIT – force line endings to be ignored


Today, I was driven slightly crazy when trying to see what changes I had made as I was swamped with files which only had differences in their line endings when running a git status.

After trying a lot of different options this was the only one that worked without having to clone the complete repository.

git config --global core.safecrlf false
git diff --name-only
git config --global core.safecrlf true # Best to set this back after finding out what files changed.

Tip: After committing the files returned by ‘git diff –name-only’, run ‘git reset –hard’ to discard all other local file changes. WARNING – this will discard any non-committed files.


GIT Commit Message Hook on Windows (without Admin Rights)



To get GIT to prevent a commit unless your commit message contains a certain format you need to use a GIT commit-msg hook.

To create the hook you need to create a hooks folder under your .git folder within each GIT repository. Within the .git/hooks folder place your commit-msg file.

The following commit-msg script makes sure that your commit message must start with the text “[Mobile]” – maybe Mobile is your team name.


error_msg="Aborting commit. Your commit message is missing '[Mobile]' at beginning of comment."

if ! grep -iqE "$commit_regex" "$1"; then
 echo "$error_msg" >&2
 exit 1

To have one central commit-msg file create a junction (if you don’t have Window’s Administrator Rights) or a symlink if you prefer, but you’ll need admin rights.

For example, if you have a repository called my-app and your central hooks folder is stored in your “OneDrive for Business” folder.

cd C:\Users\philip.murphy\Documentes\my-app\.git\
mklink /J /D hooks "C:\Users\philip.murphy\OneDrive for Business\hooks"

You should do this for each repository. Now when you update the central commit-msg file, all repositories will reflect your new commit message hook rules.

BTW, if you want to initially populate your commit comment with some text:

git config --global commit.template "C:\Users\philip.murphy\OneDrive for Business\committemplate.txt"

It may contain the text that you want to initially populate the comment message with:


Note for SourceTree users. The commit-msg hook works well, but the commit template doesn’t.


Example output of commit being prevented as comment doesn’t begin with [Mobile].

How to restart Chrome – really


Simple one you’d think, but sometimes it is difficult to make sure that you’ve shutdown and restarted Chrome properly after making some configuration change to the browser. With multiple independent tabs and with ‘keep running in the background’ turned on, it can become a chore to complete this simple task. Type the following into the address bar and you are fully reloaded.


Get your Local Web Application to pull data from a Remote Server


Sometimes when you have a web application deployed to your local host it is more convenient to get the data for it from a remote host. Add the following to the end of your apache2\conf\httpd.conf to redirect all requests for the localhost/ws endpoint to a remote one (will require an Apache restart).

# Pull data from another host instead of localhost.
SSLProxyEngine On
ProxyPass /ws https://remote.host/ws
ProxyPassReverse /ws https://remote.host/ws

Note: SSLProxyEngine allows this to work with HTTPS URLs.

If you want to exclude a request from being redirected to the remote host, and instead to get data from your local machine add the following:

ProxyPass /ws/myservice/person !

If you are using Tomcat or JBoss with jk_mod you may also need to add the following to allow the resource to be serviced locally:

JkUnMount /ws/myservice/person ajp13

Handy GIT commands


Pull latest changes while doing a rebase.

git pull --rebase origin master

Merge from a branch back to master

git merge --no-ff --no-commit <branch-name>

–no-ff : preserve the branch structure and not just place branch commits on top of master branch.

–no-commit: Don’t auto-commit. This allows you to discard some changes first e.g. a pom.xml version number that is relevant to the merge branch, but not to the master branch.

Throw away last commit [should stash first]

git reset --hard HEAD~

Remove all changes including untracked files [should stash first]

WARNING: this will remove all untracked files as well e.g. “.bat/.sh” files that you may use to do special builds or deployments.

git clean -df
git checkout -- .