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:
- Go to https://github.com/join
- Choose a professional username, such as
firstname-lastnameorstudent-ID - 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.
- Choose a secure password and complete the sign-up form
- 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
-
Go to https://github.com/new and sign in if needed.
-
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"
- Repository name:
-
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:
- Click on the Settings tab (usually found in the top menu of the repo page).
- 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
- Open your repository on GitHub
- 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:
- Open your newly created GitHub Classroom repository in your browser
- 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
- Open Visual Studio Code (or you can download from here)
- Press
Ctrl+Shift+P(orCmd+Shift+Pon macOS) - Type and select: Git: Clone
- Paste the repository URL you copied earlier
- Choose a folder on your machine to save the cloned project
- 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
-
Create a new file named
about-me.md:touch about-me.md -
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.mdon Windows (Git Bash)open -a TextEdit about-me.mdon macOSnano about-me.mdorcode about-me.mdif using VS Code or terminal editors
-
Stage the file (tell Git to track it):
git add about-me.md -
Commit the file with a message:
git commit -m "Add about-me file" -
Push your changes to GitHub:
git push -
View the file in your GitHub repository online to confirm the update.
Option B: Using Visual Studio Code
- Open the cloned repository folder in VS Code
- Create a new file named
about-me.mdand write something inside it - Click the Source Control icon on the sidebar
- Stage the file by clicking the
+next to its name - Enter a commit message (e.g., “Add about-me file”) and click the checkmark to commit
- 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)
- Go to your repository on GitHub.
- You will see a prompt to compare & create a pull request for
feature/intro. - Click Compare & pull request, review the changes, and click Merge pull request.
- You can now delete the branch on GitHub after merging if prompted.
Option B: Using Visual Studio Code
-
Open your project folder in VS Code
-
Click on the Source Control icon (or press
Ctrl+Shift+G) -
At the bottom left of the window, click the current branch name (e.g.
main) -
In the branch menu that appears:
- Click + Create new branch
- Name it
feature/intro - VS Code will automatically switch you to this new branch
-
Create a new file called
intro.txtand write:This is a test file created on a separate branch. -
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
- Click the
-
Push the branch:
- Click the
...(three-dot menu) - Select Push
- Click the
-
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
| Command | Description | Example Usage |
|---|---|---|
git init | Initialise a new Git repository | git init |
git clone <repo-url> | Clone a repository to your local machine | git clone https://github.com/user/repo.git |
git status | Show the status of changes in your working directory | git status |
git add <file> | Stage file(s) for commit | git add index.html |
git add . | Stage all changes in the directory | git add . |
git commit -m "message" | Commit staged changes with a message | git commit -m "Initial commit" |
git push | Push commits to the remote repository | git push origin main |
git pull | Fetch and merge from the remote repository | git pull origin main |
git fetch | Download changes from remote without merging | git fetch origin |
git merge <branch> | Merge specified branch into current branch | git merge feature-branch |
git branch | List all branches | git branch |
git branch <name> | Create a new branch | git branch new-feature |
git checkout <branch> | Switch to a different branch | git checkout main |
git checkout -b <branch> | Create and switch to a new branch | git checkout -b feature-xyz |
git log | View commit history | git log |
git diff | Show changes between commits or working directory | git diff |
git rm <file> | Remove a file from the repository and staging area | git rm old_file.txt |
git reset <file> | Unstage a file | git reset index.html |
git config | View or set Git configuration options | git config --global user.name "Alice" |
git remote -v | Show URLs for remote repositories | git 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.