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¶
![](https://imgs.xkcd.com/comics/git_2x.png)
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 Version Control System (CVCS)
- Distributed Version Control System (DVCS)
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¶
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?
- Free and Open Source
- Speed
- Scalable
- Reliable
- Distributed Development
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
- Windows: Gitbash for windows users
- Mac: Download Open command line for MacOS user command line
- Linux:
sudo apt-get git
Set it up
- Add your Git username and set your email
git config –-global user.name “YOUR_USERNAME”
- Configure you email address for uploading
git config -–global user.email “jSmith@mail.com”
- Check if you have an SSH KEY already (If you see a long string starting with ssh-rsa, you can skip the ssh-keygen step)
cat ~/.ssh/id_rsa.pub
- Generate your SSH key
ssh-keygen -t rsa -C "$your_email"
- Now let´s see your keygen
cat ~/.ssh/id_rsa.pub
- Copy your key
(windows) clip < ~/.ssh/id_rsa.pub
(mac) pbcopy < ~/.ssh/id_rsa.pub
(linux) xclip -sel clip < ~/.ssh/id_rsa.pub
- Finally add the copied key to GIT on the web version
Clone your site¶
- Navigate to the folder where you want to put or create your repo
- Clone your student repository
git clone git@gitlab.com:flu/mdef19-20-templateblogpage.git
Upload your repo¶
-
Add the new files you added to git git add index.html to upload file by file git add . to upload all the files at once
-
To download the last copy from the repository git pull (for downloading the last copy of the repository)
-
To have a working copy of your repo git merge (to have a working copy)
-
Now name your update, so you know what you changed with this push. git commit -m ‘change you did’
-
Upload to the Repository git push
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¶
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¶
- dir - To view the contents of a directory, type “dir”
- del - Subsequently, you might want to clean up useless files
- clip - copy the output
UNIX specific¶
- ls - list files in a folder
- rm
- delete files. Be careful, it won’t ask for confirmation and they won’t be in the Trash!! - pbcopy - copy the output
All¶
- cd
- It is frequently useful to know in which directory you are currently working To move between directories, use the cd command with the name of a directory example go to desktop is “cd Desktop” - cd .. go up a directory
- open
open a file with the default - mkdir
- To create a new directory - pwd - print name of current/working directory
- ls –help - show help of ls command.
- ls -a - list files in a folder (including hidden).
- ls -l - show long listing format.
- man ls - Format and display the on-line manual pages.
- mv [-f | -i | -n] [-v] source target - change name or ~~move file~~ to specific folder
- cat
- outputs file into std_output
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¶
- echo “Hello” > file.txt: Says hello, but redirects the output to a file (file.txt). Creates a new file
- echo “Hello” >> file.txt: Says hello, but redirects the output to a file (file.txt). Appends it to the file
Pipeline¶
Pipelines are meant for command to command communication.
- pwd|pbcopy: send the output of pwd command to the input of another command, in
- ps -ax|grep ‘python’: send the output of ps -ax (list of open processes) and only grab the ones that contain python in them
Terminal specific features¶
- tab - Executable search path. autocomplete the name during the process of type.
- double tab - show all the options to autocomplete.
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!