The Linux terminal and version control

Site: ΕΛ/ΛΑΚ Moodle
Course: 3D printing with circuits and Arduino
Book: The Linux terminal and version control
Printed by: Guest user
Date: Thursday, 12 December 2024, 3:16 PM

1. Terminal basics

The Terminal is an interactive, text-based interface for your Operating System. When you type a command, you're basically telling your computer to do something very specific. Many commands will print information to the screen. Some will ask for input, and others may just return you to a prompt.

The quickest way to install, remove or update applications is through the Terminal. The Terminal is also referred to as the shell, command line, prompt, or command prompt.

To open a Terminal, tap the Super Key , to search your computer and type the word Terminal.

A box like the one below will appear:

Terminal

Navigating The Terminal

It might not look like much, and at first glance there might not appear to be much information, but the Terminal is one of the most powerful tools at your disposal. Take a look:

Terminal Overview

Section Description
Current User The username of the person currently logged in to this Terminal.
Current Host The hostname of the system currently in use by the Terminal. Unless you've connected to a remote machine via SSH, this will be the same name as your computer.
Current Directory The current folder that this Terminal resides in. Commands entered and files modified are scoped to this folder, unless providing an absolute path to another file or folder, or if the command is available in the user's $PATH. Basically, the Terminal can only see into this folder. A tilde (~) indicates the user's home directory.
Prompt Anything entered after this symbol is interpreted as a command.
Typed Command Anything that is typed into the Terminal is shown after the prompt.
Cursor A visual indicator of the user's current position in the Terminal.

As you change folders and move throughout your computer, the prompt will change in response. In many cases, you won't need to move around to run a command.

To list all files and folders in the current directory, type ls. To change directories (folders), type cd [directory name]. To go back up a directory type cd ... At any time, you can press the Tab key to have the Terminal guess the completion for your entry, or twice to show all possibilities.

Moving around

Running Elevated Commands

In most cases, the Terminal prevents you from damaging your system by requiring authentication or elevated privileges to run certain commands. For example, to check for updates you will need to prepend the command apt update with sudo. Below is an example of the same command, ran once without sudo and once with.

Using sudo

When you run a command with sudo in front of it, you'll be prompted for your password. When typing your password, you won't see anything. Just enter your password and then press Enter. If it's entered incorrectly, the Terminal will let you know and give you another chance to enter your password.

Useful Commands:

sudo apt update

This command will tell your system to search for potential updates and advise if there are any available, but this command does not install them.

sudo apt upgrade

This command will download and apply any updates to your System76 computer.

sudo apt full-upgrade

This command will upgrade your packages and installs or remove packages to resolve dependencies so everything is up-to-date.

sudo apt install [application]

This will install a particular application and its dependencies on your computer.

sudo apt purge [application]

This will remove a program and it's configuration files from your computer.

man sudo

The man command is short for manual. You can type the man command in front of any command that you want more information about.




--

This page is a version of the System76 article on Terminal basics.

2. Git basics

Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.

Version control is a system that records changes to a file or set of files over time so that you can recall specific versions later.

What is VCS? (Git-SCM) • Git Basics #1 from GitHub on Vimeo.

Getting a Git Repository

You typically obtain a Git repository in one of two ways:

  1. You can take a local directory that is currently not under version control, and turn it into a Git repository, or

  2. You can clone an existing Git repository from elsewhere.

In either case, you end up with a Git repository on your local machine, ready for work. Here we will explain how to do the second.

Cloning an Existing Repository

If you want to get a copy of an existing Git repository — for example, a project you’d like to contribute to — the command you need is git clone. Every version of every file for the history of the project is pulled down by default when you run git clone. In fact, if your server disk gets corrupted, you can often use nearly any of the clones on any client to set the server back to the state it was in when it was cloned.

You clone a repository with git clone <url>. For example, if you want to clone the Git linkable library called libgit2, you can do so like this:

 git clone  https://github.com/libgit2/libgit2

That creates a directory named libgit2, initializes a .git directory inside it, pulls down all the data for that repository, and checks out a working copy of the latest version. If you go into the new libgit2 directory that was just created, you’ll see the project files in there, ready to be worked on or used.

If you want to clone the repository into a directory named something other than libgit2, you can specify the new directory name as an additional argument:

 git clone https://github.com/libgit2/libgit2 mylibgit

That command does the same thing as the previous one, but the target directory is called mylibgit.


content adapted from git-scm.com

3. Cloning Otto from github

Otto is completely open source. All its designs, code, libraries and material live on a Github page. Github is a a web-based hosting service for version control using that uses Git.

Because the Otto robot development is constant and run by a vibrant community, it makes no sense to host these files on the server of this course. This is why we are now going to clone the Otto folder locally.

The clone button provids the url to use with git:

We will now open a Terminal application and git clone it!

git clone https://github.com/OttoDIY/DIY.git