Tallaght Campus

Department of Computing

Source code management in CSWD

  1. git

    git

    Git is a version control system, used for managing software source code. Among other things, it allows the user:

    • to group source code into repositories, which can be stored locally (on a PC) or remotely (in the cloud)
    • to keep track of the history of changes to a source code repository
    • to branch changes for the purpose of creating divergent versions of a source code repository
    • to easily merge changes in with changes made by other users on the same source code repository

    In this module you will be using git to upload and update your lab work in GitHub.

  2. GitHub

    GitHub

    GitHub is primarily a hosting service for source code repositories stored in the cloud.

    It allows users to work with their repositories through a git interface i.e. it 'speaks git'.

    It provides various other tools (e.g. for collaborative work) and services (e.g. GitHub Pages, the website hosting service used by these notes!).

    GitHub is not the only repository hosting service. Other examples are Gitlab and Bitbucket.

    In this module we use GitHub only as a repository hosting service.

  3. Running git

    Running git

    Git needs to be installed in order to be used (it is not part of any operating system).

    • It is installed on the lab PCs.
    • Installation files can be downloaded from here.

    Git commands can be run from:

    • a command line
    • a GUI
    • within an IDE

    In this module you will be using git on the command line.

  4. git commands

    git commands

    Git consists of many commands. The full documentation can be found here.

    For this module, all your lab work will be stored in a single repository. Also, you will need to use only the small subset of git commands listed here.

    To run any of these commands, you must open a command line window (cmd or PowerShell in Windows; Terminal in Linux) and type the commands into the window.

    • Before you do anything else, git requires that you identify yourself. Use the following commands to register your name and email address with git:
      git config --global user.name "<your name (not username)>"
      lets git know your name
      git config --global user.email "<the email address with which you registered with GitHub>"
      lets git know your email (this should be the email you registered on GitHub with)
    • To start working on a lab (either from scratch or to continue lab work previously uploaded to GitHub), you need to make a copy of the online (GitHub) repository on your computer. You do this by cloning the repository with the following command:
      git clone <repository URL>
      clones a repository to your computer file system (a repository working directory is created in the directory where the command was executed)
    • Now you can work on your code. For code changes to pertain to the repository you cloned in the previous step, they must be made inside the repository working directory. You may create directories and delete them and you may create, modify or delete files, but all this must take place within the repository working directory.
    • To commit your changes to the repository (record them in the repository) locally, use the following two commands (in the order that they are listed), with the repository working directory as the current directory:
      git add .
      moves any modified files or files new to the repository into the 'staged' state
      git commit -m "<some comment describing the changes>"
      commits the staged files, but does not push them to the online repository
    • To push the changes to the online repository in GitHub, use the following command, with the repository working directory as the current directory:
      git push
      pushes the commited changes to the online repository
    • To check if the updates to the repository have been successfully pushed to GitHub, open your GitHub account on the WWW and have a look at the contents of the CSWD lab repository.