How I run this site - part 2 of 7 - GitHub

20 November 2020

So how do I manage files and versions?

I work from several different computers from different places.
It is always a challenge to know how to always work with the latest version of a file. How to keep everything up to date on all computers.
Additionally, you may want to save different versions of files for recordkeeping.

The simple and obvious choice is to use Git implemented by GitHub.
Learn more about Git at Wikipedia. GitHub is free for personal projects, and you find it at

You then have a centralized repository with all the files in the latest version and earlier versions.

GitHub is easy to use, and you do not need many commands to work with it.
Github is available for most platforms; Windows, Mac and Linux. I run all these operating systems myself.

After creating a free user profile on GitHub, you can create a project.

To set it up on a new computer, navigate to the desired directory in the terminal and type:

git clone "url to project"
For example:
git clone

This downloads all files with the defined directory structure.

Next time you work on the project, go to the same directory and just type in the terminal:
git pull
That's it! Now your local repository is 100% in sync.

When you have finished working on the files and want them uploaded to the GitHub repository, you need to commit the files and then upload them.
Since I work alone with this website, I do not have to think about whether others have checked out files etc.

You can do this in (at least) three different ways.

1. Manually in the terminal

As before, navigate to your local GitHub directory in the terminal and type:
git add.
git commit -m "your message here"
git push

2. Create a bash script

To avoid writing all three "add", "commit" and "push" each time, create a simple bash script or create an alias (see bulletpoint 3 below).

Open the terminal and type:

In Vim: Press I for insert mode and type these four lines:
git add.
git commit -m "'$ *'"
git push

Press Esc, then press :wq (to write and quit).

And then make the file executable with:
chmod +x

Put the file in a directory located in your path. For example the /bin directory.

Then just type:
./ My comment for this version

3. Make an alias

This is the way I roll.
Most people have their aliases in either ~/.bashrc or ~/.bash_aliases

Open the file as follows:
vim ~/.bash_aliases

In Vim:
Press I for Insert mode and type these lines:
gitpush_function () {
    git add.
    git commit -m "$ *"
    git push
alias gitpush = gitpush_function

Press Esc, then press :wq (to write and quit).

To get the new alias valid, type in the terminal:
source ~/.bashrc

So in the future you now just write:
gitpush My comment for this version

That was it!

PS! You can find simple explanations of all the Git commands here: Git Guides

The next time I have to work with the web pages - no matter which computer - I run the same routine. Starts the computer, opens the terminal and navigates to my git directory, and then "git pull".

Do the work I'm going to do.

And then I finish my work by just typing "gitpush This is my comment".

This was part 2 of 7. Have you read part 1? Part 3 is coming soon and will cover how I write my text.