Git and GitHub Workshop

Author

Workshop Team

Published

15 April 2025

Git and GitHub Workshop

Audience: First-year Master’s students (new to coding and version control)
Objective: By the end of these instructions, you will be able to:
βœ… Create a GitHub repository
βœ… Clone it to your computer
βœ… Make changes, commit them, and push updates to GitHub


πŸ“Œ Why Use Git and GitHub?

Git is a tool that helps you track changes in your code over time. GitHub is a platform that stores your code online and allows you to share it with others.

With Git and GitHub, you can:

  • Keep a history of your changes
  • Work on projects from different computers
  • Collaborate with others easily

πŸ› οΈ Setup Requirements

βœ… Install Git on your computer:

  • MacOS: Open Terminal and install Git using Homebrew:
brew install git
  • Windows: Download and install Git from https://git-scm.com.

  • Linux: Install Git using your package manager:

sudo apt install git

βœ… Create a GitHub account:


1. Create a Repository on GitHub

  1. Open https://github.com and log in.
  2. In the top-right corner, click the + icon β†’ New Repository.
  3. Fill out the repository details:
    • Repository name: my-first-repo
    • Description: (Optional)
    • Set it to Public (or Private if preferred)
    • Check Add a README file
  4. Click Create repository

βœ… You’ve created your first repository!


2. Clone the Repository to Your Computer

  1. Open your repository on GitHub.
  2. Click the green Code button β†’ Select SSH β†’ Copy the SSH URL.
  3. Open a terminal (Command Prompt, Git Bash, or similar).
  4. Navigate to a directory where you want to store your project:
cd ~/Documents
  1. Clone the repository:
git clone git@github.com:your-username/my-first-repo.git
  1. Change into the repository folder:
cd my-first-repo

βœ… You’ve now downloaded a local copy of your repository.


3. Make Changes to a File

  1. Open the repository folder in a text editor (like VS Code).
  2. Open the README.md file.
  3. Add a line of text:
This is my first repository for my coding project.
  1. Save the file.

βœ… You’ve made your first change!


4. Stage, Commit, and Push Changes

Now you need to tell Git to track and save these changes.

πŸ‘‰ Step 1: Check the Status

In the terminal, check which files have changed:

git status

You should see the README.md file listed as modified.


πŸ‘‰ Step 2: Stage the Changes

Stage the file so Git knows to track it:

git add README.md

πŸ‘‰ Step 3: Commit the Changes

Create a snapshot of the changes and add a descriptive message:

git commit -m "Added personal message to README"

πŸ‘‰ Step 4: Push the Changes

Send the changes to GitHub:

git push

βœ… Check your repository on GitHub β†’ Refresh the page β†’ Your new content should be visible!


5. Make More Changes (Optional)

  1. Open the README.md file again.
  2. Add another line of text:
Here’s a second change to my repository.
  1. Save the file.

πŸ‘‰ Repeat the Git Workflow

  1. Check status:
git status
  1. Stage the change:
git add README.md
  1. Commit the change:
git commit -m "Added second line to README"
  1. Push the change to GitHub:
git push

βœ… Refresh your GitHub repository to confirm the update.


6. How to Check the History

To see a history of your commits, type:

git log
  • Press q to exit the log view.

7. Troubleshooting Tips

πŸ’‘ Permission denied when cloning?
- Make sure your SSH key is set up correctly. Follow GitHub’s guide on setting up SSH keys here.

πŸ’‘ Git asks for your username and password?
- You might not be using SSH. Double-check that you copied the SSH URL, not the HTTPS one.

πŸ’‘ Changes aren’t showing on GitHub?
- Make sure you’ve pushed your changes:

git push

βœ… Workflow Summary

  1. Make changes – Edit your files.
  2. Stage changes – git add <filename>
  3. Commit changes – git commit -m "Message"
  4. Push changes – git push

🎯 What Success Looks Like

βœ… A GitHub repository created.
βœ… Files cloned to your local machine.
βœ… Successfully edited, committed, and pushed changes to GitHub.


πŸš€ Next Steps

  • Try adding more files and making more commits.
  • Explore creating a branch and making a pull request.
  • Experiment with resolving conflicts and merging branches.

πŸ‘ Well Done!

You’ve completed the Git and GitHub workshop. Version control will now make your coding projects more organized and stress-free!