Git and Github

Extension on the Skills Development hands-on session 4

The session is comprised of three parts:

  • Command Line Interface

  • Git

  • GitHub

Follow these guides along the presentation to learn more about Git and Github.

Command Line Interface

The Command Line Interface or CLI allows us to pass commands to the computer in the form of lines of text, with the aim to manage files, run programs and interact with the computer in general. A Graphical User Interface is simply allowing the end user to work with CLI commands in an easier interficie.

Each operative system uses a different CLI, with their specific languages:

  • Linux: the Linux CLI is named Terminal, and it uses Bash commands to operate

  • MacOS: the MacOS CLI is named Terminal, and it uses Bash commands except in the newest versions, that use zshell.

  • Windows: Windows has two different CLIs, the Command Prompt, which uses its own language, and the PowerShell (Windows PowerShell or PowerShell 7.0), which use cmdlet and is more similar to the widespread Bash.

For Windows users, we recommend working with PowerShell 7.0, and, if possible, using a Windows Subsystem for Linux, where a Linux machine is installed inside Windows.

Basic CLI commands

CommandActionLanguage

cd <foldername>

Change directory to foldername

bash, cmdlet

cd ..

Go one directory up

bash, cmdlet

ls

List directory contents

bash, cmdlet

mkdir

Make a new directory

bash, cmdlet

mv <filename> <path/folder>

Move a file to the specified folder destination

bash, cmdlet

cp <filename> <path/folder>

Copy a file to the specified folder destination

bash, cmdlet

rm <filename>

Removes a file

bash, cmdlet

rm -r <foldername>

Removes a folder

bash, cmdlet

nano <filename>

Creates a new file

bash

notepad <filename>

Creates a new file

cmdlet

Git

Software for version control, allowing to track changes in a folder (Git Repository) such as new files, removed files or content edits. It is particularly useful for collaborative projects where several people contribute to the same folder.

You can think of Git as a never ending undo command

Installation

  1. Download Git source code for your operating system

  2. Follow the instructions on your screen to complete installation

  3. Windows users should take into account the following options while installing Git:

    1. Select Run Git from the Windows Command Prompt on the Adjusting your PATH environment screen. This will automatically connect Git to your Command Prompt CLI.

    2. Select Checkout Windows-style, commit Unix-style line endings on the Configuring line ending screen. This will prevent conflicts when working across different operating systems

Most Linux distributions come with Git installed by default

Git can be accessed from a number of GUIs, but to understand how it works we will use the CLI commands.

Git CLI commands

CommandAction

git config --global user.name

Sets you Git username (it will identify your commits, both internally and on remote repositories

git config --global user.email

Set your email address to identify your user

git init

Create a new git repository

git status

List changes and files to add or commit

git add <filename>

Add a file to the staging area

git add .

Add all files to the staging area

git commit -m <>

Commit changes to Git (not to a remote repository)

git clone

Copy an online repository to your local system

git push

Push changes to from your local system to the online repository

git pull

Update your local repository with the newest version online.

GitHub

GitHub is a code hosting platform for version control and collaboration. It lets you and others work together on projects from anywhere. It is based on Git.

GitHub account

To work in GitHub you need to create an account (free). If you don't have one, head over to https://github.com/join and follow the instructions.

GitHub Repositories

You can create a new GitHub repository for each project. The basic considerations when starting a new repository are:

  • Public or private: public repositories can be seen by anyone, but the owner retains control over who can contribute to it. Private repositories are only visible to the owner and invited participants.

  • README file: the readme file appears on the first page of the repository. It is a Markdown file and contains the basic information about the project. You can read more about the importance of a good README file here.

  • gitignore: a rule to ignore certain types of files, for example build artifacts. Read more about it.

  • License: the license file is one of the most important files in your repository, since it will indicate to external users and contributors what they can and can't do with your code. Check the full list of approved Open Source Licenses.

Working with GitHub Repositories

GitHub is an online platform that uses the Git tracking system. You can copy repositories from GitHub in your local computer, work with them and update the changes via git to the online repository, to effectively collaborate with others. There are three key Git commands designed to work with online repositories:

git clone: copies a repository to your system

git push: after adding and commiting your files to Git, you need to push changes to the online repository

git pull: if you have an older version of an online repository (for example because another contributor has pushed its changes), you need to pull the changes before working.

In this session we will not look further into working with GitHub, you can read more about branching and contributing to third party repositories here.

Last updated