Version Control

Our problem

How many times have you done this?

project_final.doc
project_final_final.doc
project_final_final_this_one.doc
project_final_final_this_one_yes.doc
project_final_final_final_mega_final.doc

Our solution

source: https://xkcd.com/1597/

Version Control is the management of changes to documents, computer programs, large websites and other collection of information. There are two types of VCS:

Centralized VCS

Centralized version control system (CVCS) uses a central server to store all files and enables team collaboration. It works on a single repository to which users can directly access a central server.

Drawbacks: - It is not locally available; meaning you always need to be connected to a network to perform any action. - Since everything is centralized, in any case of the central server getting crashed or corrupted will result in losing the entire data of the project.

Distributed VCS

In Distributed VCS, every contributor has a local copy or “clone” of the main repository i.e. everyone maintains a local repository of their own which contains all the files and metadata present in the main repository.

Git

Git-logo.svg
By Jason Long - http://git-scm.com/downloads/logos, CC BY 3.0, Enlace

What is git?

Git is a distributed version control system for tracking changes in source code during software development. It is designed for coordinating work among programmers, but it can be used to track changes in any set of files. Its goals include speed, data integrity, and support for distributed, non-linear workflows.

Why Git?

Git Local/Remote Structure

As a reference, this is a basic structure of the local/remote structure using git.

Note

Getting started

Install Git

Note

All information is here

Digest

Set it up

git config –-global user.name “YOUR_USERNAME”
git config -–global user.email “jSmith@mail.com”
cat ~/.ssh/id_rsa.pub
ssh-keygen -t rsa -C "$your_email"
cat ~/.ssh/id_rsa.pub
(windows) clip < ~/.ssh/id_rsa.pub
(mac) pbcopy < ~/.ssh/id_rsa.pub
(linux) xclip -sel clip < ~/.ssh/id_rsa.pub

Video on how to do it

Clone your site

git clone git@gitlab.com:flu/mdef19-20-templateblogpage.git

Upload your repo

Guidelines

Login

Students can login on gitlab using their email address (the one they use for registration) and entering their Student ID as a temporary password (they need to change it asap)

Permissions & Access control

Students are Master in their repository, useful to delete large files Instructors are Master in the lab group, so they are also Master in the student’s projects and in the website Instructors can message individual students opening tickets on their individual sites If instructors need to create other projects inside the group for example a local project, or a local issue tracker they can do so independently, and add students as members.

Sizes

There’s a soft limit on 300mb. Sites reaching 300mb will be listed on a dedicated page in the archive for public shame. Site over 300mb for two weeks in a row will get special consideration.

Pro tip

Image optimization and why to do it: Automating Image Optimization

Tips and tricks

Check the file-size of your folder! You should commit 1-2MB per week. Not more! Run the following command (Terminal or GitBash) in your folder to see folder and file-sizes:

du -sk * | sort -n

Each time you want to update your website, you should go through the following commands:

```
cd ~/Desktop/fablabbcn
git pull
<change files - modify the files in your folder> 
git status
git add .
git commit -m "<commit message>"
git push
```

Commit message

Write a meaningful commit message. This should answer the question:

“If I apply this commit, I will… “.

For example:

“uploading final project idea”.

Note

If you end up in Vim-Editor, quit without saving by typing: :q!

Warning

Your website might not update in your Browser until you clear the cache (Hard Refresh!)

If you still get error messages, study git or write an email to your instructor.

Introduction to the terminal

Everything is a FILE

Everything is a file.

Each file in your computer resides somewhere (in a directory), and each program in your computer is a file, hence, they live somewhere. You can know where they live, and make some programs yourself. But don’t be afraid, the only thing you need is a file.

Each program has an specific input and an specific output. These are know as std_in and std_out. For instance, a text editor can have a text input from your keyboard and an output to a file.

Every program on your computer has the ability to do a vast amount of different things. Read files, start other programs, do math, control devices. The main difference between bash and most other programs is that unlike them, bash was not programmed to perform a certain task. Bash was programmed to take commands from you, the user. To do so efficiently, a “language” was created which allows users to “speak” to the bash program and tell it what to do. This language is the bash shell language and you are about to become intimately familiar with it.

In essence, a shell program is one that provides users with an interface to interact with other programs. There is a large variety of shell programs, each with their own language. Some popular ones are the C shell (csh), Z shell (zsh), Korn shell (ksh), Bourne shell, Debian’s Almquist shell (dash), etc. Bash (also called the Bourne Again shell) is currently the most popular and ubiquitously available shell. Even though all of these shells use seemingly similar syntax, it is important to be fully aware of what shell you’re actually writing code for. Often, you’ll hear people refer to their code as “shell code”, which is about as specific as “source code” is when referring to your Java code. This guide will teach you how to write bash shell code: you should use it only with the bash shell, not any other.

Note

Probably the best guide to learn what this all means.

TL;DR

Bash is a simple tool in a vast toolbox of programs that lets me interact with my system using a text-based interface.

Useful commands

WINDOWS specific

UNIX specific

All

Redirection and pipelines

We can redirect the std_out of a command to a specific target. Most commonly, this can be a file

Basic redirection and appending

Pipeline

Pipelines are meant for command to command communication.

Terminal specific features

In terminal applications

VI(M) Screen-oriented text editor originally created for the Unix operating system.

Important: - Edit a file: type i - > INSERT MODE - Exit INSERT MODE: press Esc - Quit. Out of any mode: type :q - Write and quit. . Out of any mode: type :wq - Dont’ write and quit. Out of any mode: type :q!

Resources