MSc Project -CMP060L050H: Workshop 3

Part-1 GitHub Basics: Setting Up Git and GitHub

In this set of activities, you will get hands-on experience with Git and GitHub, which are essential tools for managing and tracking changes in your code, documentation, and data. These skills are widely used in industry and academia and will support your MSc final project.


Step 1: Create a GitHub Account

GitHub is a cloud-based platform that allows you to store and manage your code, track changes over time, and collaborate with others. It’s widely used in both academia and industry.

If you don't have an account already, please follow the instructions below:

  1. Go to https://github.com/join
  2. Choose a professional username, such as firstname-lastname or student-ID
  3. Use your university email address to access educational features (e.g. private repositories, GitHub Student Developer Pack). You can link it to mutiple emails later.
  4. Choose a secure password and complete the sign-up form
  5. Verify your email address to activate your account

Why this matters:
You will use GitHub to store your MSc project work, track your progress, and possibly collaborate with others. Starting with a well-named, verified account sets you up for future success.

Step 2: Install and Configure Git

Git is a version control system that allows you to manage your project files over time. It keeps track of every change you make, so you can revisit earlier versions, collaborate with others, and avoid losing work.

Install Git

Install Git based on your operating system:

  • Windows: Download and install from https://git-scm.com/download/win
    During installation, accept the default settings. This will also install Git Bash, which You will use as your terminal.

  • macOS: Download and install from https://git-scm.com/download/mac
    Alternatively, open the Terminal and type:

    xcode-select --install
    
  • Linux (Ubuntu/Debian):

    sudo apt update
    sudo apt install git
    

Open Your Terminal

  • On Windows, open Git Bash from the Start Menu
  • On macOS/Linux , open the Terminal application from Launchpad or Spotlight

Verify Git Installation

Check that Git is installed by typing:

git --version

Configure Git (One-Time Setup)

Now set your name and email. This information will be recorded in every change you make:

git config --global user.name "Your Full Name"
git config --global user.email "your.email@example.com"

Check your configuration with:

git config --list

Further Reading

To learn more about Git commands and concepts, visit the official documentation: https://git-scm.com/doc

Why this matters:
Git needs to know who you are to track your work. Setting this up ensures your commits are properly attributed and helps when collaborating with others.

Step 3: Create a New Repository on GitHub

A repository (or "repo") is a project folder on GitHub. It holds all your code, documentation, and version history. You can create one to store your MSc coursework, dissertation code, notes, or even experiment logs.

Create a New Repository

  1. Go to https://github.com/new and sign in if needed.

  2. Fill in the following:

    • Repository name: git-practice-lab (or a name relevant to your project)
    • Description: Optional, but useful for summarising the purpose of the repo
    • Visibility: Select Private so only you (and optionally your lecturer) can access it
    • Tick the box "Initialize this repository with a README"
  3. Click Create repository

GitHub will set up your repository and take you to its main page. You will see your README.md file, commit history (currently just one), and options for cloning the repo to your computer.

Explore Repository Settings

After creating the repository:

  1. Click on the Settings tab (usually found in the top menu of the repo page).
  2. Take a few minutes to explore:
    • General settings like repo name, visibility, and description
    • Branches to manage default branches and protection rules
    • Collaborators (you can add contributors if needed later)
    • Pages, Webhooks, and other features

Why this matters:
Creating your own repository gives you full control over your project. You can store scripts, datasets, results, and documentation all in one place, and access it from anywhere.

Step 4: Clone the Repository to Your Machine

To work on your GitHub project locally (on your own machine), you need to clone the repository. Cloning downloads the files and Git history into a folder on your computer.

You have two options:

Option A: Use the Repository You Just Created

  1. Open your repository on GitHub
  2. Click the green Code button and copy the URL under HTTPS

Example:

https://github.com/your-username/git-practice-lab.git

Option B: Use a GitHub Classroom Repository

  • For this session, I have set up a GitHub Classroom that will automatically create a private repository linked to your GitHub account.
  • Please click https://classroom.github.com/a/qqntlbBw and follow the on-screen instructions to join the assignment.
  • Once your personal repository is created:
    1. Open your newly created GitHub Classroom repository in your browser
    2. Click the green Code button and copy the URL under HTTPS

Clone Using the Command Line (Git Bash / Terminal)

Open your terminal (Git Bash for Windows, Terminal for macOS).

Then run the following command, replacing the URL with the one you copied earlier from the Code button on GitHub:

git clone https://github.com/your-username/repository-name.git

For example, if you copied:

https://github.com/your-username/git-practice-lab.git

You would type:

git clone https://github.com/your-username/git-practice-lab.git

Then move into the project folder:

cd git-practice-lab

This creates a local folder on your machine containing the contents of your GitHub repository.


Clone Using Visual Studio Code

  1. Open Visual Studio Code (or you can download from here)
  2. Press Ctrl+Shift+P (or Cmd+Shift+P on macOS)
  3. Type and select: Git: Clone
  4. Paste the repository URL you copied earlier
  5. Choose a folder on your machine to save the cloned project
  6. Click Open when prompted

VS Code will now treat this folder as your working project, connected to Git.


Why this matters:
Cloning connects your local machine with your GitHub repository. This allows you to work offline, use your preferred tools, and then push changes back to the cloud for backup, version tracking, or collaboration.


Note:
If you don’t want to install anything on your machine, you can also try GitHub Codespaces (if enabled). It’s like a full coding environment in your browser, it is useful for quick edits or working from different devices.

Look for the "Code" > "Open with Codespaces" option in your repository.

More info can be found here

Step 5: Basic Git Workflow

Once you’ve cloned your repository, you can start working on it locally. Git tracks every change you make, allowing you to manage versions, backtrack if needed, and collaborate effectively.

You can use either the command line or Visual Studio Code GUI.


Option A: Using the Command Line

  1. Create a new file named about-me.md:

    touch about-me.md
    
  2. Open the file in a text editor and write a short paragraph about yourself. For example:

    My name is [Your Name].
    I am studying MSc in [Your Course].
    I am interested in [e.g. cybersecurity, data analysis, AI].
    

    You can open it using:

    • notepad about-me.md on Windows (Git Bash)
    • open -a TextEdit about-me.md on macOS
    • nano about-me.md or code about-me.md if using VS Code or terminal editors
  3. Stage the file (tell Git to track it):

    git add about-me.md
    
  4. Commit the file with a message:

    git commit -m "Add about-me file"
    
  5. Push your changes to GitHub:

    git push
    
  6. View the file in your GitHub repository online to confirm the update.


Option B: Using Visual Studio Code

  1. Open the cloned repository folder in VS Code
  2. Create a new file named about-me.md and write something inside it
  3. Click the Source Control icon on the sidebar
  4. Stage the file by clicking the + next to its name
  5. Enter a commit message (e.g., “Add about-me file”) and click the checkmark to commit
  6. Click the ... (three-dot menu) and choose Push

Why this matters:
These steps make up the core Git workflow. You will use them repeatedly throughout your MSc project to save progress, sync with GitHub, and keep your work organised and secure.


Step 6: Create and Merge a Branch

You can skip this and move to Github Actions

In Git, a branch is a separate workspace that allows you to make changes without affecting the main version of your project. This is useful for testing new ideas or working on features before you're ready to add them to the main branch (usually called main or master).

Why this matters:

Branches help you experiment, manage features separately, and avoid breaking your main work. This is especially useful during your MSc project when you may want to try different approaches without disrupting your core work.


Option A: Using the Command Line

1. Create a new branch

From your terminal:

git checkout -b feature/intro

This creates a new branch called feature/intro and switches to it.

2. Create a new file and add some content

touch intro.txt

Then open it and add something like:

This is a test file created on a separate branch.

Save the file.

3. Stage and commit the file

git add intro.txt
git commit -m "Add intro.txt on feature branch"

4. Push the branch to GitHub

git push --set-upstream origin feature/intro

5. Open a Pull Request (PR)

  1. Go to your repository on GitHub.
  2. You will see a prompt to compare & create a pull request for feature/intro.
  3. Click Compare & pull request, review the changes, and click Merge pull request.
  4. You can now delete the branch on GitHub after merging if prompted.

Option B: Using Visual Studio Code

  1. Open your project folder in VS Code

  2. Click on the Source Control icon (or press Ctrl+Shift+G)

  3. At the bottom left of the window, click the current branch name (e.g. main)

  4. In the branch menu that appears:

    • Click + Create new branch
    • Name it feature/intro
    • VS Code will automatically switch you to this new branch
  5. Create a new file called intro.txt and write:

    This is a test file created on a separate branch.
    
  6. Save the file, then stage and commit it via the Source Control panel:

    • Click the + to stage
    • Enter your commit message (e.g., “Add intro.txt on feature branch”)
    • Click the checkmark to commit
  7. Push the branch:

    • Click the ... (three-dot menu)
    • Select Push
  8. Open GitHub in your browser

    • You’ll see a prompt to open a Pull Request
    • Click Compare & pull request, then Merge pull request

Common Git Commands Overview

CommandDescriptionExample Usage
git initInitialise a new Git repositorygit init
git clone <repo-url>Clone a repository to your local machinegit clone https://github.com/user/repo.git
git statusShow the status of changes in your working directorygit status
git add <file>Stage file(s) for commitgit add index.html
git add .Stage all changes in the directorygit add .
git commit -m "message"Commit staged changes with a messagegit commit -m "Initial commit"
git pushPush commits to the remote repositorygit push origin main
git pullFetch and merge from the remote repositorygit pull origin main
git fetchDownload changes from remote without merginggit fetch origin
git merge <branch>Merge specified branch into current branchgit merge feature-branch
git branchList all branchesgit branch
git branch <name>Create a new branchgit branch new-feature
git checkout <branch>Switch to a different branchgit checkout main
git checkout -b <branch>Create and switch to a new branchgit checkout -b feature-xyz
git logView commit historygit log
git diffShow changes between commits or working directorygit diff
git rm <file>Remove a file from the repository and staging areagit rm old_file.txt
git reset <file>Unstage a filegit reset index.html
git configView or set Git configuration optionsgit config --global user.name "Alice"
git remote -vShow URLs for remote repositoriesgit remote -v

Extra:

Below you can learn more about:




Author: Dr Ali Jaddoa
Email: Ali.Jaddoa@roehampton.ac.uk

Thank you for reading this MDBook. If you have any questions or suggestions, feel free to reach out.