Git: Remotes

FAIR & Reproducible Teaching with Quarto & Git
Course at University of Hamburg
Slides | Source
License: CC BY 4.0

13:00

Schedule

Day 1

Day Date Time Title
1 2026-03-20 09:30 - 10:00 Welcome & Introduction
1 2026-03-20 10:00 - 10:30 Quarto: Introduction
1 2026-03-20 10:30 - 10:45 Quarto: Presentations
1 2026-03-20 10:45 - 11:00 Git: Setup & Configuration
1 2026-03-20 11:00 - 11:15 Command Line
1 2026-03-20 11:15 - 12:00 Git: Basics
1 2026-03-20 12:00 - 13:00 Lunch Break
1 2026-03-20 13:00 - 14:00 Git: Remotes
1 2026-03-20 14:00 - 15:00 Git: Collaboration
1 2026-03-20 15:00 - 15:30 Quarto: Publication to GitHub Pages
1 2026-03-20 15:30 - 16:00 Git: Tags & Releases

1 Last session

Last session: Learning objectives

After the last session, you should now be able to answer the following questions / do the following:

đź’ˇ You can initialize a Git repository.
đź’ˇ You can check the status of a Git repository.
đź’ˇ You understand the difference between the staging area and a commit.
đź’ˇ You can stage and commit changes.
đź’ˇ You understand the difference between a commit message and a description.

2 This session: Git: Remotes

Objectives

đź’ˇ You can create a remote repository.
đź’ˇ You can connect your local Git repository to a remote repository service like GitHub or GitLab.
đź’ˇ You can pull and push changes to and from a remote repository.
đź’ˇ You can clone a repository from a remote repository.

Reading

Remotes - Introduction

Tasks

In this session, you will work on the following tasks:

  1. Reading: Read the chapter(s) Remotes - Introduction in the Version Control Book.
  2. Implementation: Try out the commands in the chapter.
  3. Exercises: Work on the exercises.

As always:

  1. Try out the commands of this session and play around with them.
  2. Check whether you have achieved the learning objectives.
  3. Ask questions!

Exercises (1)

Mandatory for everyone!

Connect to remote repositories using SSH

  1. Generate an SSH key.
  2. Copy the SSH key to your clipboard.
  3. Add the SSH key to the remote repository (for example, GitHub or GitLab).

Upload your local repository to a remote repository

  1. Create an empty repository on the remote repository hosting platform, for example GitHub or GitLab. Make sure to not initialize the repository with any files!
  2. If needed, navigate to your project repository using the command line.
  3. Set the remote URL of your local repository to your remote repository.
  4. Push the changes on your default branch (main or master) to your remote repository.

Exercises (2)

Collaboration Option 1 (Basic)

Private collaboration on default branch (main or master)

  1. Add your exercise partner as a collaborator to your project repository on GitHub.
  2. Clone your partner’s repository.
  3. Add a new change to your collaborator’s project file (if you are unsure, where to add the entry, ask your collaborator!)
  4. Add and commit the changes.
  5. Push the changes to the remote repository.
  6. Pull your partner’s changes into your repository.

Exercises (3)

Collaboration Option 2 (Advanced)

Private collaboration with pull requests (using GitHub Flow)

  1. Add your exercise partner as a collaborator to your project repository on GitHub.
  2. Clone your partner’s repository.
  3. Create a new branch in your collaborator’s repository.
  4. Add a new entry to your collaborator’s project file (e.g., .txt or .qmd (if you are unsure, where to add the entry, ask your collaborator!)
  5. Add and commit the changes.
  6. Push the changes on the new branch to the remote repository.
  7. Create a Pull Request (on GitLab: Merge Request).
  8. Review the Pull Request that your collaborator made in your repository.
  9. 🚀 Optional: Add additional changes on the branch pushed by your collaborator.
  10. Merge the pull request into your repository.

Exercises (4)

Collaboration Option 3 (Alternative)

Clone and sync your repository

  1. Move to a location on your computer where you want to clone a repository.
  2. Clone your remote repository to a different location on your computer.
  3. Stage and commit changes in the new location (consider using a new branch).
  4. Push these new changes to GitHub.
  5. Pull the changes to the repository in the original location.
  6. Delete your newly cloned repository.

🚀 Bonus exercises

Add a README.md

  1. Find the option to create a new file on your remote repository in the browser.
  2. Name the file README.md, add a brief description, and provide a commit message.
  3. 🚀 Optional: Play around with Markdown syntax.
  4. Save the README.md file to the repository.
  5. Pull the changes to your local repository.

3 Appendix

How does SSH work? The key and padlock analogy

Figure 1: “Understanding public key private key concepts” by Blake Smith (License: Unknown; Source on GitHub)
  • When you set up SSH, you generate a key pair: the private key stays on your device, while the public key is copied to the servers you want access to.
  • Think of your public key as a padlock. You can make lots of copies of this padlock and distribute them to different places - servers, computers, or anything you want to secure (just like sharing a padlock to secure different lockers). These places install your padlock, but no one can open it because they don’t have your key.
  • Your private key is the actual key that opens those padlocks. You keep it safe and never share it. As long as your key stays secure, it doesn’t matter how many padlocks you’ve distributed.
  • When you try to connect to a server, SSH checks if the padlock (public key) on that server matches your key. If they match, the door opens.

Warning: “The authenticity of host can’t be established”

TL;DR: Enter yes and hit Enter.

The following message might appear when connecting to GitHub for the first time via SSH:

#| code-copy: false
The authenticity of host 'github.com (140.82.121.3)' can't be established.
ECDSA key fingerprint is SHA256:nThbg6GUVB7ZdnZ3iXYvgIhXZOL7NXqb7A4s9F8XY7w.
Are you sure you want to continue connecting (yes/no/[fingerprint])?

This message indicates that your system is trying to connect to a remote server (i.e., GitHub) over SSH for the first time, but it doesn’t yet trust the server’s identity.

If you are trusting the server’s identity, enter yes and hit Enter. This will result in the following message:

#| code-copy: false
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.

This message indicates that the GitHub server’s public key has been added to your ~/.ssh/known_hosts file permanently, so you won’t be prompted with this warning the next time you connect to GitHub over SSH.

After a successful push, you will get a message like this:

#| code-copy: false
Enumerating objects: 17, done.
Counting objects: 100% (17/17), done.
Delta compression using up to 8 threads
Compressing objects: 100% (12/12), done.
Writing objects: 100% (12/12), 2.11 KiB | 2.11 MiB/s, done.
Total 12 (delta 9), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (9/9), completed with 5 local objects.
To https://github.com/username/repository.git
   fb3efef..8f50685  main -> main

Cloning

Cloning

  • Remember to clone a repo in a sensible location (not in your own repository)
  • To rename the cloned repo you can use: git clone <URL> new-folder-name

4 Solutions

Solutions: Connect to remote repositories using SSH

Code
#!/bin/bash

1ssh-keygen -t ed25519 -C "your_email@example.com"
2cat ~/.ssh/id_ed25519.pub
3# Copy the SSh key to your account
1
In the command line, create a new SSH key. Make sure to change the example email to your email address. Optionally, provide a passphrase.
2
Copy the SSH key to your clipboard. Here, we use cat to print the contents of the SSH key to the command line. Copy the contents displayed in the Terminal to your clipboard.
3
Add the SSH key to your remote repository account.

Solutions: Upload your local repository to a remote repository

Code
#!/bin/bash

1# create an empty remote repository
2cd my-project
3git remote add origin https://github.com/your-username/your-repo-name.git
4git push -u origin main
1
To create an empty repository on GitHub: (1) Go to GitHub and click the + icon in the upper-right corner, then select New repository. (2) Name your repository. (3) Do not select Initialize this repository with a README. (4) Click Create repository.
2
Optional: Navigate into the project repository using cd (or a similar path).
3
Set the remote URL of the local repository to the repository using git remote add origin <URL>. Remember to use the correct <URL> depending on whether you authentication method (typically SSH or PAT).
4
Push the changes on the default branch (here, main) to the remote repository using git push -u origin main.

Solutions: Private collaboration with pull requests (using GitHub Flow)

Code
#!/bin/bash

1# Add your exercise partner as a collaborator to your recipes repository
2cd ~
3git clone https://github.com/partner-username/partner-repo-name.git
4git checkout -b new-branch-name
5echo "New Recipe" >> recipes.txt
6git add recipes.txt
git commit -m "Add new recipe to recipes.txt"
7git push origin new-branch-name
8# Create a Pull / Merge Request.
9# Review the PR your partner made in your repository.
10# Merge the PR into your repository.
1
Add your exercise partner as a collaborator to your recipes repository: (1) Go to your repository on GitHub. (2) Click on Settings. (2) Click on Manage access in the left sidebar. (3) Click Invite a collaborator and enter your partner’s GitHub username.
2
Move to the location on your computer where you would like to clone your partner’s repository into, using cd in the command line. Here, we cd into the user’s home directory (~).
3
Clone your partner’s repository using git clone. Make sure that you not cloning into an existing repository.
4
Create a new branch in your partner’s repository.
5
Add a recipe to your partner’s recipes.txt file.
6
Add and commit the changes using a descriptive commit message.
7
Push the changes on the new branch to GitHub.
8
Create a Pull Request: (1) Go to your partner’s repository on GitHub. (2) Click Compare & pull request for your branch. (3) Provide a title and description, then click Create pull request.
9
Review the PR your partner made in your repository: (19) Go to your repository on GitHub. (2) Click on the Pull requests tab. (3) Click on the PR made by your partner. (4) Review the changes and provide feedback.
10
Merge the PR into your repository: (1) After reviewing, click the green Merge pull request button. (2) Click Confirm merge.

Solutions: Clone and sync your repository

Code
#!/bin/bash

1cd /new/location/for/repo
2git clone https://github.com/your-username/your-repo-name.git /new/location/for/repo
3git checkout -b new-branch
echo "New Recipe" >> recipes.txt
git add recipes.txt
git commit -m "Add new recipe to recipes.txt"
4git push -u origin new-branch
5cd /original/location/for/repo
git fetch
git switch new-branch
6rm -rf /new/location/for/repo
1
Move to the location on your computer where you would like to clone your own repository into, using cd in the command line.
2
Clone your repository from GitHub to a different location on your computer.
3
Stage and commit changes in the new location (consider using a new branch).
4
Push the new changes to GitHub.
5
Fetch these new changes to the repository in the original location.
6
Delete your newly cloned repository.

Solutions: Add a README.md

  1. In your browser, go to your remote repository (for example, on GitHub), click Add file, and select Create new file.
  2. Name the file README.md. Add a brief description of your project. Provide a descriptive commit message at the bottom.
  3. Play around with Markdown syntax
  4. Click the green Commit new file button to save the README.md file to the repository.
  5. Use git pull origin main to pull the changes to your local repository.