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 |
This session
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 for the
recipes
project. - Quiz: Test your knowledge with the quiz.
As always:
- Try out the commands of this session and play around with them.
- Check whether you have achieved the learning objectives.
- Ask questions!
- Let’s git started!
Learning objectives
At the end of this session, you should be able to answer the following questions and / or achieve the following learning 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.
recipes
project
At the end of this session, you should have accomplished the following:
- You created a GitHub account.
- You connected your GitHub account to your local Git using SSH.
- You created a new private(!) GitHub repository.
- You uploaded (i.e., “pushed”) the default branch of your
recipes
repository to GitHub.
Collaboration Option 1:
- You invited a partner from the course as a collaborator to your
recipes
on GitHub. - You collaborated on a shared project by adding and committing changes to your partner’s repository.
Collaboration Option 2:
- You clone your own repository to a different location on your computer.
- Stage and commit changes in the repository in this new location.
- Push the changes to GitHub and pull them in the original repository location on your computer.
Optional:
- You created a short
README.md
file in your repository.
Please keep the recipes
folder! We will continue to use it in the following sessions.
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 (
main
ormaster
) to your remote 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.
“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.,
.txt
or.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.
🚀 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.md
file to the repository. - Pull the changes to your local repository.
Slides
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.