Logo

4,222 Introduction to Programming

Lecture 3: Git and GitHub for collaboration

Dr. Aurélien Sallin

2026-03-06

Goals for today

At the end of this lecture and exercise session, you will:

  • know how to go remote with our repository
  • be able to collaborate using Git and GitHub
Remember: practice, practice, practice!
  • It can feel overwhelming at first, but it gets easier with time and experience.
  • Start working with Git and GitHub as soon as possible, for instance for your group projects in Data Analytics II 😉

Recap: Git Basics

Recap: Git workflow

Fill out the blanks.

Git workflow

  • A typical repository contains a mix of files: source code (R scripts, Python scripts, etc.), output files (like quarto documents or csv files), and configuration files (like .gitignore).
  • Basic workflow: git initgit addgit commit
  • Key concepts: Working directory → Staging area → Repository
  • Use .gitignore to exclude files you don’t want to track.

Recap: Git commit history

Fill out the blanks.

Recap: Branches and merging

  • Branches let you work on features without breaking main code.
    git switch -c feature → make changes → git commit
  • Merging brings changes from one branch into another.
    git switch maingit merge feature
  • Merge conflicts happen when changes overlap. Resolve manually, then commit.

Remotes 🌐️

Communicate and collaborate via remotes

The main reason to use Git is to collaborate with others and back up your files online.
  • Think of projects like:
    • Group project in Data Analytics II in R
    • Group project for Introduction to Programming in Python
    • Any project you want to share with others (e.g., your portfolio, open-source contributions, etc.)

Communicate and collaborate via remotes

  • So far you’ve tracked your own work locally.
  • To collaborate with others, we need a remote
  • GitHub is the de facto standard with a big community

Remotes 🌐️

What is a remote?

  • A remote is a version of your repository stored on a website like GitHub.

What is GitHub?

  • GitHub is a website to host Git repositories
  • By having your Git repository online, you can easily collaborate with others
  • There are alternative hosts like Bitbucket or GitLab

Why having your code on GitHub?

  • Backup of your projects (work from different machines, from work to private, or from one firm to another…)
  • Collaboration in groups and also with people you don’t know
  • Free and Open-Source Software (FOSS)
  • Visibility as a programmer (show your portfolio and your “productivity” as a programmer… GitHub fulfills some signaling function and works as a social network for programmers)

Github.com: a demo

Check some interesting GitHub repositories:

Or GitHub pages:

Working with remotes

Four basic commands to work with remotes

  • Connect to a remote: git clone / git remote
  • Sync with the remote: git pull / git push
  • The main remote is usually called origin.
  • Remotes also have branches, just like your local repository.

Connect to a remote by remote adding it from an existing repository

When you want to add an existing repository to GitHub, you will have to add the remote yourself

git remote add <remote name> <remote URL>

Example:

git remote add origin git@github.com:asallin/BECON_4222_Introduction_Programming.git


Note 1: It only works if the remote repo exists and if you are not in a repo which has already been linked to a remote.

Note 2: To learn about all possible commands for remotes use -h, like git remote -h.

Connect to a remote by git clone-ing a repository

  • You can download repositories from GitHub (and anywhere else), by cloning them
  • For public repositories, git clone just works, for private ones you will need to be authenticated
  • If you use git clone, the remote named origin is set up for you automatically.
  • git clone <remote URL>

Syncing Changes: Pull and Push

Syncing Changes: overview

You first pull the latest changes from the remote…

… and then push your own changes.

Getting Changes: git pull

  • To get the newest updates from GitHub, type git pull in your terminal.
  • This command downloads any changes from the online repository and adds them to your current work.
# Pull from the tracked remote branch
git pull

# Pull from a specific branch
git pull <remote> <branch>

Getting Changes: git pull

  • git pull does two things under the hood: it fetches the latest changes and merges them into the current branch.
  • (You can also run git fetch to fetch the latest changes and then git merge <remote>/branch to merge them)

Note

When you run git pull for the first time, Git might prompt you to choose a default merge strategy. When you receive the message, run:

# Default to merge
git config pull.rebase false

Pushing Your Changes: git push

  • You can send your changes to GitHub by running git push
  • This only works if there are no new changes at the remote
  • If there have been changes since your last pull you need to pull again.
  • Why?
# Push to the tracked remote branch
git push

What if a branch has no upstream when pushing?

The “upstream” is the remote branch your local branch is linked to and syncs with.

  • You are on branch test2, created locally but never pushed on remote.
  • Running git push from the branch leads to the following message:
fatal: The current branch test2 has no upstream branch.
To push the current branch and set the remote as upstream, use

    git push --set-upstream origin test2
  • Use git push -u origin test2 or git push --set-upstream origin test2 to push the branch and set the upstream at the same time.
  • Both commands are equivalent (-u is short for --set-upstream)

What if a branch has no upstream when pulling?

  • You are on branch test3, which is not yet tracking any remote branch.
  • Running git pull from test3:
There is no tracking information for the current branch.
Please specify which branch you want to merge with.

    git pull <remote> <branch>

If you wish to set tracking information for this branch you can do so with:

    git branch --set-upstream-to=origin/test3 test3

Note: The easiest way to avoid both situations: always use git push -u origin <branch> the first time you push a new branch.

Push and pull

Connecting Git and GitHub

Authenticating with GitHub 🗝️

… set it up once,

…done forever as long as you don’t change computer,

… takes about 10 minutes …

Authenticating with GitHub 🗝️

Authentication when pushing and pulling

  • When you connect to a GitHub repository, GitHub needs to verify who you are using a username and password. There are several secure methods available.
  • We’ll use SSH keys: you keep a private key on your computer and upload the matching public key to GitHub; when they match correctly, GitHub grants access.
  • Using SSH keys is more secure than passwords and avoids repeated credential prompts.

How to?

  • Setting up the authentication with GitHub could be tedious the first time, but worth it 😒
  • Please go to this website from LMU Munich and follow the steps to authenticate with GitHub.
    Credits: Open Science Center at LMU Munich (Mike Croucher & Malika Ihle)

Short words on SSH Keys

What are SSH keys?

  • SSH (Secure Shell) uses a key pair (a private key which stays on your computer and a public key which is uploaded to GitHub) to authenticate without a password.
  • When you connect, GitHub checks if your private key matches the public key on file. If yes, access is granted, no password needed.

SSH keys are per machine

  • Your SSH key is tied to the computer where it was generated. If you switch to a new laptop, you need to generate a new key and add it to GitHub again
  • You can have multiple public keys registered on GitHub (one per machine)

Note: Never share your private key. Not by email, not on GitHub, not anywhere. It belongs to .gitignore.

Test your connection

Once you’ve set up your SSH key, test your connection using the following code.

ssh -T git@github.com
> Hi ASallin! You've successfully authenticated, but GitHub does not provide shell access.

Cloning a repository

Cloning the course repository

How to clone the course repository will be covered in the exercise session, but here is a quick overview of the steps.

Cloning the course repository

Remember our course structure:

Introduction_to_programming/
├── github_course_materials/ # is empty for now, you will clone the git repo in week 3
├── exercises/               # Student's own work
│   ├── week_01/
│   ├── week_02/
│   ├── ...
│   ├── week_12/
├── group_project/
│   ├── ...

Cloning the course repository

2. Find the HTTPS or SSH on the GitHub course repo

Go on https://github.com/ASallin/BECON_4222_Introduction_Programming and click on <>Code

You can find the remote URL by going to a repository on GitHub and clicking the Code button

Clone the course repository

3. Clone the course repository.

The course is public, so cloning via HTTPS will work without a SSH key.

Using HTTPS (no SSH key needed)

git clone https://github.com/ASallin/BECON_4222_Introduction_Programming.git

Using SSH

git clone git@github.com:ASallin/BECON_4222_Introduction_Programming.git

Cloning the course repository

Now you’ve cloned the course repository in your directory. You’ll have a new folder called BECON_4222_Introduction_Programming. You can remove the github_course_materials folder.

Introduction_to_programming/
├── BECON_4222_Introduction_Programming/
├── exercises/               # Student's own work
│   ├── week_01/
│   ├── week_02/
│   ├── ...
│   ├── week_12/
├── group_project/
│   ├── ...

Every week, you can refresh the course content with git pull.

Note: this is experimental. The course materials uploaded on Canvas every week are the official version. If you want to use the GitHub repository, make sure to pull the latest changes before starting to work on the exercises.

Create a repository

Creating a GitHub repository

  1. On your GitHub account, click New repository

  2. Choose the parameters:

  • Name (e.g., git-practice-week03)
  • Visibility: Public (anyone can see) or Private (only you and collaborators)
  • Add a README file

The README.md

  • First thing visitors and collaborators see when they open your repo
  • Written in Markdown (same syntax as Quarto)
  • Should describe: what the project is, how to install/run it, how to contribute
  • A good README makes your project accessible and professional
# GoldenEye Weapon System – Analysis

Economic impact of the GoldenEye satellite on financial markets.

## How to run
1. Install dependencies: `uv sync`
2. Run the analysis: `uv run python goldeneye.py`

## Data
SEVERNAYA station sensor logs, 1995. Source undisclosed.

Scenario 1: You already have a local repo and want to push it to GitHub

You’ve been working locally and now want to publish your project on GitHub.

  1. Create an empty repo on GitHub (no README, no .gitignore)
  2. Link your local repo to it and push:
git remote add origin https://github.com/ASallin/git-practice-week03.git
git push -u origin main

Scenario 2: You start from scratch: you create the repo on GitHub and clone it locally

Create the repo on GitHub first, then clone it locally:

git clone https://github.com/ASallin/git-practice-week03.git
  • It’s that simple 😎

GitHub from basics to more advanced features

Pull Requests (PRs)

A pull request (PR) is a request to merge changes from one branch into another.

Why?

  • When collaborating with other people, it’s often good to review each other’s changes
  • This is easiest done by using pull requests
  • You don’t push directly to main: you work on a branch, then request for your changes to be reviewed, pulled and merged
  • PRs are the standard way to collaborate on GitHub

Pull requests: Overview

Overview of the pull requests page in a GitHub repository. Repository: https://github.com/worldbank/GEEST

Pull requests: Detailed View

View of a single pull request on GitHub. Repository: https://github.com/worldbank/GEEST

Workflow

  1. Create a branch and make your changes
  2. Push the branch to GitHub: git push -u origin my-branch
  3. On GitHub, open a Pull Request from my-branchmain (you are usually invited to do so)
  4. Collaborators review, comment, request changes
  5. Once approved, merge the PR

PRs keep the main branch clean and give the team a chance to review code before it’s integrated.

I find PRs to be flexible (enough), and very helpful to avoid merge conflicts.

When Should you Start using PRs?

  • Maybe your project doesn’t need these features yet, but try it
  • Often it makes sense to use pull requests even when collaborating with just a few people
    • To avoid merge conflicts
    • Also for reviewing each others changes
  • Many companies require code reviews and using PRs

A rule of collaboration

Nobody pushes directly to main, everyone works on a branch and contributes via a pull request.
  • Avoids headaches with impossible merge conflicts
  • Keeps a collaborative approach

Advanced Git and GitHub
(not exam-relevant📕)

Advanced Git and GitHub

There are many more features of Git and GitHub that we won’t cover in this course. You’ll learn the rest when you need it (I still discover so many new things in Git).

In Git:

  • Hooks: trigger scripts on certain Git events (e.g., pre-commit, post-merge)
  • Rebasing: an alternative to merging that creates a cleaner commit history

In GitHub:

  • GitHub Issues: track bugs, tasks, and feature requests
  • GitHub Pages: host static websites directly from a GitHub repository
  • GitHub Actions: automate workflows (e.g., run tests, deploy code)
  • Forking: create your own copy of someone else’s repository to experiment with changes without affecting the original

Issues

  • System to track tasks that still need to be done
  • Allows for discussion
  • When an issue is done, it is “closed”

Forking

  • You can easily copy public repositories into your own GitHub account, by forking them
  • This way, you get your own remote version of the respository
    • You can still contribute your changes back to the original repository
    • The two repositories stay linked on GitHub
  • This happens in GitHub not Git

GitHub Pages

  • Host your own website there for free on GitHub Pages
  • You can create websites for specific projects (i.e. repositories)
    • <your_gh_username>.github.io/<your_repo_name>
  • Special repository name: <your_gh_username>.github.io to create a personal page (portfolio, blog, etc.)

Create a page in 10mn from a template:

  • Go to https://github.com/arifszn/gitprofile and fork the repository
  • Enable GitHub Pages (→ Settings) and GitHub Actions (→ Actions)
  • Look at the website at https://<your-username>.github.io/gitprofile/
  • Configure gitprofile.config.ts to customize your profile page.

GitHub Pages and Quarto Websites

Quarto website

  • You can also create a Quarto website and host it on GitHub Pages. Check out the Quarto documentation for more details.
  • Basic and static
You can fork them and start from there

Going Beyond
(not exam-relevant 📕)

Thanks Jan Simson for the inspiration on this chapter

Visualizing Git repositories

Several tools exist to visualize git repositories. These can be useful to get a quick overview of a git repository.

Additional resources

Conclusion

What we have covered so far

Week 1 — Getting started

  • Terminal, file paths, naming conventions
  • IDEs and VS Code
  • The importance of virtual environments for Python, with uv

Week 2 — Local version control with Git

  • Tracking changes: git add, git commit, .gitignore
  • Branches and merging; resolving conflicts

Week 3 — Collaborating with GitHub

  • Connecting local repos to GitHub (clone, push, pull)
  • Pull requests as the standard review workflow
You are now ready for the next step: Python 🐍!

Let’s get our hands dirty!

Practical: A Summary exercise

This is a guided demo exercise to practice the full collaborative workflow using GitHub and pull requests.

  • Create teams of 2 people.
  • Open the exercise document ex03_git_collaboration.qmd and follow the instructions.
  • For this exercise to work, you need to have installed Git and set up your GitHub account with SSH keys.
  • If you haven’t done that yet, participate actively with the demo.

I need two volunteers!

Sources