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.
Tasks
In this session, you will work on the following tasks:
- Reading: Read the chapter(s) Remotes - Introduction in the Version Control Book.
- Implementation: Try out the commands in the chapter.
- Exercises: Work on the exercises.
As always:
- Try out the commands of this session and play around with them.
- Check whether you have achieved the learning objectives.
- Ask questions!
Exercises
Connect to remote repositories using SSH
- Generate an SSH key.
- Copy the SSH key to your clipboard.
- Add the SSH key to the remote repository (for example, GitHub or GitLab).
Upload your local repository to a remote repository
- 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!
- If needed, navigate to your project repository using the command line.
- Set the remote URL of your local repository to your remote repository.
- Push the changes on your default branch (
mainormaster) to your remote repository.
Private collaboration on default branch (main or master)
- Add your exercise partner as a collaborator to your project repository on GitHub.
- Clone your partner’s repository.
- Add a new change to your collaborator’s project file (if you are unsure, where to add the entry, ask your collaborator!)
- Add and commit the changes.
- Push the changes to the remote repository.
- Pull your partner’s changes into your repository.
Private collaboration with pull requests (using GitHub Flow)
- Add your exercise partner as a collaborator to your project repository on GitHub.
- Clone your partner’s repository.
- Create a new branch in your collaborator’s repository.
- Add a new entry to your collaborator’s project file (e.g.,
.txtor.qmd(if you are unsure, where to add the entry, ask your collaborator!) - Add and commit the changes.
- Push the changes on the new branch to the remote repository.
- Create a Pull Request (on GitLab: Merge Request).
- Review the Pull Request that your collaborator made in your repository.
- 🚀 Optional: Add additional changes on the branch pushed by your collaborator.
- Merge the pull request into your repository.
Clone and sync your repository
- Move to a location on your computer where you want to clone a repository.
- Clone your remote repository to a different location on your computer.
- Stage and commit changes in the new location (consider using a new branch).
- Push these new changes to GitHub.
- Pull the changes to the repository in the original location.
- Delete your newly cloned repository.
🚀 Bonus exercises
Add a README.md
- Find the option to create a new file on your remote repository in the browser.
- Name the file
README.md, add a brief description, and provide a commit message. - 🚀 Optional: Play around with Markdown syntax.
- Save the
README.mdfile to the repository. - Pull the changes to your local repository.
Slides
NoteHow can I download the slides as a PDF file?
To export the slides to PDF, do the following:
- Toggle into Print View using the E key (or using the Navigation Menu).
- Open the in-browser print dialog (CTRL/CMD+P).
- Change the Destination setting to Save as PDF.
- Change the Layout to Landscape.
- Change the Margins to None.
- Enable the Background graphics option.
- Click Save.
Note: This feature has been confirmed to work in Google Chrome, Chromium as well as in Firefox.
Here’s what the Chrome print dialog would look like with these settings enabled:
These instructions were copied from the Quarto documentation (MIT License) and slightly modified.