Session 8: Remotes - Introduction

Track, organize and share your work: An introduction to Git for research

Course at University of Hamburg & Erasmus University Rotterdam

Slides | Source

License: CC BY 4.0 DOI

December 06 2024 (10:15 am)

1 Admin

Schedule

No Date Title Contents Reading Survey/Quiz
1 2024-10-18 Introduction to version control Organizational matters
Overview of seminar sessions
Introduction to version control
Introduction to Git and its advantages
Intro to version control Course introduction Survey
2 2024-10-25 Command line File Systems
Benefits of the Command Line
Basic Command Line commands
Command Line Command Line Quiz
3 2024-11-01 Setup + Git Fundamentals Installation and configuration of Git
Initializing a Git repository
Basic Git commands
Installation, Setup, First steps with Git Installation Survey, Git Basics Quiz
4 2024-11-08 Basic Git workflow Practicing basic Git commands
Ignoring files with .gitignore
Good commit messages
First steps with Git Git Basics Quiz
5 2024-11-15 Git Essentials (Repetition & Practice) Practicing basic Git commands
Ignoring files with .gitignore
Good commit messages
Git Essentials Git Basics Quiz
6 2024-11-22 Git Branching and Merging Understanding branches in Git
Creating and switching between branches
Merging branches
Resolving merge conflict
Branches Git Branches Quiz
7 2024-11-29 Quarto Workshop Introduction to Quarto
8 2024-12-06 Introduction to GitHub Introduction to remote repositories
Creating a GitHub account
Creating and managing repositories on GitHub
Pushing and pulling changes
GitHub Intro GitHub Quiz
9 2024-12-13 GitHub with collaborators Cloning a remote repository
Branching and merging in a collaborative environment
Pull Requests
GitHub Issues
Graphical User Interfaces (GUIs), e.g., GitKraken
GitHub Intro, GitHub Issues GitHub Quiz
10 2024-12-20 Repetition and Practice Repetition and Practice
11 2025-01-10 Git(Hub) with the world Forking a remote repository
README files
Project Management
GitHub Advanced, GitHub Issues GitHub Quiz
12 2025-01-17 Publishing Creating Tags with Git
Creating Releases with GitHub
Zenodo for publishing
Tags and Releases
13 2025-01-24 Graphical User Interfaces Course evaluation
Repetition and practice
Intro to Graphical User Interfaces
Graphical User Interfaces
14 2025-01-31 Summary & Outlook Course evaluation results
Surprise
Summary & Outlook

2 Last session: Quarto Workshop

Last session: Quarto Workshop

https://lennartwittkuhn.com/version-control-course-uhh-ss24/sessions/session06

Last session: Questions about Quarto?

Cool, Quarto, but what now?

  • We encourage you do use the city-guide.qmd from now on to develop your city-guide project!
    • You can move all content from city-guide.txt to city-guide.qmd.
    • Motivation: We can later turn your city-guide repository into a website (see Lennart’s example)
  • You can also just continue using the city-guide.txt file.
  • Reminder: It’s about implementing the Git exercises. It does not matter if you use a .qmd, .txt or another file.

3 This session: Remotes - Introduction

Remotes - Introduction

Image from Techdobz

Reading

“Remotes: Introduction”

Learning objectives

Remotes - Introduction

💡 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.

Cheatsheet

Command Description
git remote Manages remote repositories
git clone Creates a local copy of a repository
git pull Fetches and merges the latest changes from a remote repository into the current branch
git fetch Updates remote tracking branches
git push Uploads local commits to a remote repository

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 for the city-guide project.
  4. Quiz: Test your knowledge with the quiz.

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!
  4. Let’s git started!

city-guide project

At the end of this session, you should have accomplished the following:

  1. You created a new private(!) GitHub repository using SSH.
  2. You set the remote URL of your local city-guide Git repository.
  3. You uploaded (i.e., “pushed”) the default branch (main or master) of your city-guide project to GitHub.
  4. You invited Lennart (lnnrtwttkhn) and Reza (rezahakimazar) to your city-guide repository.

Please keep the city-guide folder! We will continue to use it in the following sessions.

Today’s team topic

  • Interview each other about your favorite place for a night out (dinner 🥘, drinks 🍹 , dance 💃, concert 🎵).
  • Add the recommendation of your partner to your text file or Quarto file.
  • Help each other in completing the exercises.

Exercises

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.

Bonus exercises

🚀 Optional: 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.

🚀 Optional: 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.

Solutions

Connect to remote repositories using SSH

Code
#!/bin/bash

ssh-keygen -t ed25519 -C "your_email@example.com" # <1>
cat ~/.ssh/id_ed25519.pub # <2>
# Copy the SSh key to your account # <3>
  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

# create an empty remote repository # <1>
cd my-project # <2>
git remote add origin https://github.com/your-username/your-repo-name.git # <3>
git push -u origin main # <4>
  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

🚀 Optional: 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.

Solutions

🚀 Optional: Clone and sync your repository

Code
#!/bin/bash

cd /new/location/for/repo # <1>
git clone https://github.com/your-username/your-repo-name.git /new/location/for/repo # <2>
git checkout -b new-branch # <3>
echo "New Recipe" >> recipes.txt # <3>
git add recipes.txt  # <3>
git commit -m "Add new recipe to recipes.txt" # <3>
git push -u origin new-branch # <4>
cd /original/location/for/repo # <5>
git fetch # <5>
git switch new-branch # <5>
rm -rf /new/location/for/repo # <6>
  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.