Portable Git

A few months back I posted an article about setting up a portable Python environment. I think just as important as having a nice environment to work in is having all your stuff properly backed up for when things go wrong!

I use Git to properly keep track of all changes I have made to programming projects, journal articles and conference papers. I am also using it to backup and keep tabs on my final dissertation. This is really useful, not just for when things go wrong but also to go back and look at previous versions of, for example, a paper where some text you later deleted is still there and can be recovered.

Setting up a portable version of Git is super easy. Just download the portable version for your operating system at this website, put it on your USB stick and use it whenever you want. The trickier part is actually creating a git repository and keeping stuff synced.

GUI environments exist for maintaining Git repositories on your computer but I actually think it is just easier to do everything from command line in this case. If you are working on these projects by yourself you can keep things relatively simple and only need to know a few basic commands. First run the ‘git-cmd.exe’ file (if you are running windows) and then use the ‘cd’ command to get to the directory you want to backup.

git init

Run this command in the folder you want to keep track of, it can contain code, pictures, documents or whatever else you want to keep backed up. So you now have an empty git repository on your computer. So as to add all the files in that folder you need to run:

git add .

So all the files are ‘staged’ or ready for commiting. Now type:

git commit -m "message telling me what this commit is"

This command ‘commits’ the ‘staged’ files in the current folder to the current ‘branch’. What this basically means is that whatever you had in the folder when you typed ‘git add .’ is now backed up as a saved point in time that you can retrieve and go back to later.

Typically you will want to save your files on a remote server (in the ‘Cloud’) so they can be retrieved from wherever you are. If you are at a university you should have access to a private GitLab account. GitHub can also be used for free if you are willing to share you work with everyone, otherwise you have to pay a small fee to keep it private. BitBucket is another hosting service that offers free accounts.

Once you have created an online repository for the project you are backing up you need to tell the Git program running on your computer where the online repository is. You should have been given a URL when you created your  online project, something like ‘https://user@gitlab.com/username/Project.git’. Once you have this you can link it up with the repository on your computer by typing:

git remote add origin https://user@gitlab.com/username/Project.git

where you should replace the above URL with your real one.

Once you have this all setup all you need to do is type:

git push -u origin master

That will send all your files over to your online repository and keep them safe. In future, whenever you want to save the current state of your folder just type these commands:

git add .
git commit -m "something about the current save"
git push

That is about all you need to know for 90% of the time. You can do the same thing on another computer and use the following command to retrieve the last saved state:

git pull

That’s it!

One other thing that can happen is you change one or two things that aren’t important on the other computer, you then wish to pull the last save and Git tells you that the two versions of that repository don’t match anymore. If that happens you can force the folder on your computer to match that of the online repository using this command:

git fetch --all
git reset --hard origin/master

That will wipe whatever changes you made on your local computer and replace it with the online version, so be careful!

You can start making things more complicated with branches representing different version histories of the same repository, but if you are just using Git to keep basic track of your work these commands are all you will need.

======== CHEAT SHEET =========
---- Start a new repository ----
git init
git remote add origin <url>

---- Save current state ----
git add .
git commit -m "message about save"

---- Upload repository to online server ----
git push -u origin master   # First time
git push   # Any time afterwards

---- Get repository from online server ----
git pull

---- Overwrite local repository with online version ----
git fetch --all
git reset --hard origin/master


I hope this helps some people get their heads around using Git. It is really useful even for small projects and I don’t think it needs to be super complicated to use.





Does energy matter?

Many of my posts are looking at how the energy efficiency of wastewater treatment can be improved. In fact one of my first posts was looking at exactly this. At large municipal wastewater treatment works that are constantly treating the waste produced by whole towns any little piece of energy they can save will help them cut costs. If we really could reduce energy usage down to zero for wastewater treatment, what sort of effect would that have on a country like Germany?

Energy usage by industry in Germany, 2014

So the energy usage of wastewater treatment is part of “Other” in the above chart. How much of “Other” is it?

Energy usage for wastewater treatment in Germany

You see that little red strip up there? That is total energy usage of all wastewater treatment plants in Germany when compared to other industries. Although only a small blip on the chart I have shown it adds up to one of the larger energy consumers for municipalities. This is all good, but what if we start looking at industry and some of the bigger pieces of the pie?

One interesting idea is to treat the highly concentrated wastewater from certain industries on-site. This makes the job of the municipal wastewater treatment works easier and should help reduce fees for wastewater disposal required by the factory. Some places where this makes sense include: paper production, milk processing, meat processing and abattoirs, and many food and beverage production facilities. The processes produce waste streams with very high organic loading, that can often be treated using anaerobic digestion.

A big advantage of anaerobic digestion that often gets touted is its ability to produce biogas as a potential energy source. This should make it super attractive to industries that need a system for treating their waste, right?

Well… Maybe. The big factor that comes into play is cost. Let’s say we are living in a perfect world where the treatment plant is running and most of the cost has been offset by the fewer waste disposal fees the factory now has to pay. What about all that biogas being produced? How much of an effect would the energy recovered from biogas production have on a large factory? Let’s have a look at energy costs for industrial use in Germany for an example week, the blue line below is the continuous average price of energy in €/MWh.

Source: https://www.energy-charts.de/power_de.htm
Source: https://www.energy-charts.de/power_de.htm

What the hell is happening at the end there?!?! The actual price of energy is negative, people are paying me to use more energy now or what? Yes, actually. Even if you ignore the negative prices (the phenomenen for which the priority given to renewable energy is often blamed) it is possible to see the change in energy prices even within a single day. If you are running a large factory and someone says you can save so and so much money by building a biogas plant and processing your waste into renewable energy and someone else comes and says you can save even more money by just running one of your production lines a bit later in the evening, which option do you choose?

So at the moment energy does matter but money matters more.