Angular Productivity: Automate git pull and deploy a different branch without getting distracted

Naguib (Nick) ihab
Jul 25, 2017 · 2 min read

Yesterday I was in “the zone”, focused and determined to debug this piece of complex spaghetti code and fix it, taking down notes, listening to some nice music when all of a sudden someone taps on my shoulder and asks me to build branch 277 for them… now I have to stash my changes on git, checkout this other branch, run git build and copy it somewhere so that they can see what’s on that branch, it’s a process that takes a couple of minutes with the build so good luck getting back into that same zone after doing that.

It’s annoying isn’t it? The good news is, almost any kind of routine job can be automated, so here’s a way to automate that by just running a windows batch file:

Step 1: Make a copy your current dev folder

You don’t want to stash or commit your changes on the existing dev folder that you’re working on, instead make a copy of that folder and make sure its pointed to the same repository

Step 2: Write this batch file

::inputs
set /P destination=Branch name:
::operations
D:
cd \Dev\App2
call git checkout %destination% — force
call git pull — force
call grunt build
xcopy “dist” “C:\xampp\htdocs\%destination%” /s/e/c/y/fstart “” http://10.0.2.65/%destination%

What you need to change is the following:
- cd \Dev\App2 << Change that to your copy of your dev folder
- xcopy “dist” “C:\xampp\htdocs\%destination%” /s/e/c/y/f << Change the path to point to your xampp folder (or whatever other lamp tool you use to host your built code locally for others to view it)
- start “” http://10.0.2.65/%destination% << If you have a local server that you share with others internally then change this ip address

You can add in there an SSH or AWS S3 upload if you want to upload whatever’s built to a remote server to share it with your clients or colleagues.

That’s it!! now when someone comes over, taps you on the shoulder and asks you to build branch 700 for them you can simple run that batch file, type in 700 and it’ll do the job, once the browser page comes up just copy the URL and send it to them.

Naguib (Nick) ihab

Written by

Founder @ upilio.io (My Guinea Pigs App)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade