Appendix C. Git Workflow

Table of Contents
Git for PBWeb
Local Start
Sharing the Local Work
Others, Those You Share With

Git for PBWeb

Git is a decentralised version control system. The best. We want to use Git for version control, backup, and as a sharing tool for professional project work and/or assignments in your studies.

Let us assume you must develop a website. In the process files must be backed up, shared between you and your codevelopers, in such a way that it is easy to experiment with the content, and try out ideas out before deciding on the final status. The website files eventually also have to be placed on one of your servers for publication on the web, of course.

All this is done easily with Git.

Git is a decentralised version control system. This means that the totality of the code of a project is available on every project member's computer. But before we get there, some project member, let us call her the initiator, project manager, must create and initialize a project and its repo, short for repository. A repo is really just a fancy name for a directory, aka folder, containing your project subdirectories, and files.

There are two ways she can get started. Locally on her own computer, or remotely, ie on a Git server on the internet.

Local Start

There are some basic tasks to be executed by the initiator:

decide on a project name, and create a directory with that name. Think in terms of Assignment2020a, or DentistReservationSite rather than Assignment 2020 a, or The Dentists Reservation System Website. A good repo name follows the rules for a good variable name in a program, one word that says it all.

It goes without saying that the repo for a web project should be placed somewhere wisely in the filesystem of your computer, eg in htdocs, or www directories.

Now she opens a terminal and in that she executes the following three commands:
mkdir projectname
cd projectname
git init

The first command creates a directory, the next positions an invisible activity pointer in it, and the third creates an empty repository in the directory, your project home. If she checks for repo content she may not see anything. Git's own files are hidden.

Do some work
Now she may create some files in the project, eg, index.html, projectname.js, … She must then make them known to Git collectively by this command:
git add .

or individually by this:

git add projectname.js

Whatever is not added is unknown to Git.

Commit your work
At this point, or indeed every time later when the project is at a natural checkpoint, eg ready to be tested, the user commits her work. This importantly makes Git do what it has to do to keep track of your work
git commit -m 'some message relevant to commit'

A commit or checkpoint is a state of your work that you may later make Git return to if some later development does not work out as expected or desired.

At this point she has done the first step in a development cycle. Now if she works alone, she may do some more work, test it, commit it, and repeat that cycle until the project or assignment is finished.

Git knows what she has done, and moreover, Git knows each commit, so that she may undo/redo work with the commits from Git. If she works alone or if she doesn't need to share the work with others, everything is fine.

Sharing the Local Work

If the above work has to be shared with someone, other project members in the same project, or just for disseminating her work, she has to look at a Git Server. If she watched the referenced videos, she was introduced to It is arguably the most well known, but there are others. Yours truly have taken a liking to, and the former of which will be used in this example. In either case she must register as a user, which for the purposes of this programme is free.

Login to the chosen server
With the menus of the server create a new repository with the same name as the local name from above.
The service will provide the necessary steps to connect the local work to this remote repo.
Logging on and creating an empty repo resulted in something like:
Figure C.1. Git Server Service Info
Git Server Service Info

So look at "Get your local …"
Then do

the following three commands

cd projectname
git remote add origin
git push -u origin master

The first points to the project directory. Not necessary if you terminal program is already there. The next is a one time command telling Git that the remote friend of this project is whatever the url says. Finally, the third command copies the local master, name of local repo, to origin, name of remote repo, at the server.

Others, Those You Share With

The beneficiaries of the sharing, it might be you as a member of the project tema, or yours truly as a teacher for correcting assignments, there are two ways of getting the repo and its content:

If you do not have the repo
When the repo is being shared to start collaboration, and as such you need it for the first time, do:
cd parentfolder
git clone
This command will create the folder projectname already initialized with git and containing the repo. Ready for work.
If you have the repo
If you already have the repo, and just need the updates others have made, do
git fetch

In either case you may go directly into the "Do some work" cycle outlined previously.