Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add exercises for ws24 #243

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
24 changes: 24 additions & 0 deletions exercises/_exercises-branches_cityguide.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
### Create and Merge a New Branch

1. **Navigate to the city guide repository using the command line.**
2. **Create a new branch called `feature`.**
3. **Switch to the new branch.**
4. **Add a new section to your `placeholder.qmd` file, such as a description of another favorite café or a local attraction in your city**
5. **Stage and commit the changes to the `placeholder.qmd` file on the `feature` branch.**
6. **Switch back to the default branch (main or master).**
7. **Merge the `feature` branch with your default branch.**
8. **Delete the `feature` branch.**

### Create and Resolve a Merge Conflict

1. **Create a merge conflict by editing the same section of `placeholder.qmd` on two separate branches:**
- On the `feature` branch, add or modify a section in `placeholder.qmd`.
- On the default branch, make conflicting changes to the same section of `placeholder.qmd`.

2. **Attempt to merge the `feature` branch with the default branch to create a merge conflict.**
3. **Resolve the merge conflict by manually editing the `placeholder.qmd` file:**
- Decide how to integrate the conflicting changes, possibly by combining content or choosing one version over the other.

4. **Stage the resolved changes in `placeholder.qmd`.**
5. **Commit the resolved changes with a descriptive commit message.**
6. **Delete the `feature` branch afterwards.**
17 changes: 17 additions & 0 deletions exercises/_exercises-cli_cityguide.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### Navigate the file system

Identify a folder on your computer where you (want to) keep course-related files.
If you don't have one, choose a suitable location in your file system.

1. Navigate into the chosen location.
2. Use the command line to display the path of your chosen folder.

### Create files and folders

3. Create a new subfolder and name it `git-course`.
4. Navigate into the `git-course` subfolder.
5. Use the command line to display the path of your chosen folder.

### Explore the File system

6. Freely explore your local file system
19 changes: 19 additions & 0 deletions exercises/_exercises-first-steps-git_cityguide.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### Connect to GitHub

1. Generate a personal access token (PAT) on GitHub.
1. Use the PAT for GitHub authentication.

### "Download" the repository for this course
1. Navigate into an appropriate place on your system
1. Go to GitHub and copy paste the URL of the course repository
1. Use `git clone` to download the repository of this course

### Add content and commit changes

1. Open the folder in RStudio as a new project
1. Open `placeholder.qmd`.
1. Ask your partner for their favorite café in their city and write it down in `placeholder.qmd`
1. Stage the changes
1. Commit the changes in `placeholder.qmd` with a descriptive commit message.

:rocket: Optional: Commit at least three additional changes in `placeholder.qmd`.
30 changes: 30 additions & 0 deletions exercises/_exercises-git-essentials_cityguide.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
### Amend a Commit

1. **Make additional changes to your `placeholder.qmd` file:**
- Imagine you've added a favorite café your city but forgot to include the neighborhood it's located in.

2. **Stage the changes:**
- Stage the `placeholder.qmd` file containing the café name and description but without the neighborhood.

3. **Amend the previous commit to include the new changes:**
- After realizing you forgot to include the neighborhood, edit the `placeholder.qmd` file to add the neighborhood information.
- Amend the previous commit to include this new detail in the same commit.

### Create a `.gitignore` File

1. **Create a random file that you want to ignore:**
- Create or download a file named `random-file.docx` or any similar file to simulate an unwanted file in your repository.

2. **Check the state of your repository:**
- Use Git to check the current state and verify that the `random-file.docx` is listed as an untracked file.

3. **Create a `.gitignore` file:**
- Create a `.gitignore` file in the root of your repository.

4. **Add the random file to the `.gitignore` file and save:**
- Add `random-file.docx` to the `.gitignore` file so that Git will ignore it.

5. **Check the state of your repository again:**
- Verify that `random-file.docx` is no longer listed as an untracked file.

6. **Stage and commit the changes in `.gitignore`:**
24 changes: 24 additions & 0 deletions exercises/_exercises-github-advanced_cityguide.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
### "Public" collaboration with pull requests (using a fork and GitHub flow)

1. Find out what [forking](https://lennartwittkuhn.com/version-control-book/chapters/github-advanced.html) is
1. **Fork the repository** of another course participant (who is not your partner from the previous exercise)
1. Create an **issue**, suggesting a missing activity to do in your city
1. Repeat the steps from the previous exercise using the forked repository:
1. **Clone** the *forked* repository into a sensible location on your computer
1. **Create a new branch** and create **one or multiple commits** "fixing" the issue that you opened
1. If available, follow the **contributing guide** of your partner's repository
1. **Push** your changes to GitHub
1. **Create a pull request** with your changes (hint: from the fork to the original repo) and refer to the issue in your pull request

### Review pull requests in your repository

1. View any pull requests that are created in your repository.
1. Review the changes made by the contributor in the pull request.
1. If needed, discuss additional changes with the contributor in the pull request.
1. Close the pull request by merging the proposed changes.

### Protect your branch

1. Go to your repository's "Settings" and select "Branches".
1. Under "Branch protection rules", click "Add rule" and enter "main" in the "Branch name pattern" field.
1. Enable the desired protection options (for example, require pull request reviews) and click "Create" to save the rule.
50 changes: 50 additions & 0 deletions exercises/_exercises-github-intro_cityguide.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
### Upload your local repository to GitHub

1. Create an empty repository on GitHub (do not initialize the repository with any files).
1. Set the remote URL of your local repository to your GitHub repository.
1. Push the changes on your `main` branch to GitHub.

### Create a `README.md` file on GitHub

1. Navigate to your repository on GitHub, click "Add file", and select "Create new file".
1. Name the file `README.md`, add a brief description, and provide a commit message.
1. :rocket: Optional: Play around with [Markdown](https://www.markdownguide.org/) syntax.
1. Click the green "Commit new file" button to save the `README.md` file to the repository.
1. Pull the changes to your local repository.

### Fetch and merge your changes

1. Run `git fetch` to retrieve the latest changes from the remote repository.
1. Run `git merge origin/main` to merge the fetched changes into your local `main` branch.
1. Verify that your local repository now includes the changes made on GitHub.

### "Private" collaboration with pull requests (using "GitHub Flow")

1. Add your partner (desk neighbor) as a collaborator to your repository.
1. Clone your partner's repository.
1. Create a new branch in your partner's repository.
1. Add your favourite bar to your partner's `placeholder.qnd` file.
1. Add and commit the changes.
1. Push the changes on the new branch to GitHub.
1. Create a Pull Request.
1. Review the PR your partner made in your repository.
1. Merge the PR into your repository.

### Manage branches

1. Push another branch (other than the default branch) with changes to GitHub.
1. Delete any unused or merged branches.

### Clean up your repository on GitHub

1. Delete unnecessary files or add a new recipe directly on GitHub.
1. Commit changes on GitHub with a message.
1. Pull the changes to your local repository.

### Clone and sync your repo

1. Clone your repository from GitHub to a *different location* on your computer.
1. Stage and commit changes in the new location (consider using a new branch).
1. Push these new changes to GitHub.
1. Pull the changes to the repository in the original location.
1. Delete your newly cloned repository.
8 changes: 8 additions & 0 deletions exercises/_exercises-setup_cityguide.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Configure Git

1. Navigate into the `git-course` folder.
1. Set your Git username.
1. Set your Git email address.
1. Change the default name of the initial branch to `main`
1. :rocket: Optional: Change your default text editor.
1. List the Git configuration settings.
99 changes: 99 additions & 0 deletions exercises/_solutions-branches_cityguide.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
### Create and Merge a New Branch

1. **Navigate to the city guide repository:**
- Use the command line to move to the directory containing your Rotterdam/Hamburg guide repository.

2. **Create a new branch:**
- Create a new branch called `feature` using:
```sh
git branch feature
```

3. **Switch to the new branch:**
- Switch to the `feature` branch using:
```sh
git switch feature
```

4. **Add new content to `placeholder.qmd`:**
- Add a new section, for example:
```markdown
## Another Favorite Café in Rotterdam
Hopper Coffee: A modern café located in the center, known for its excellent pastries and spacious seating.
```

5. **Stage and commit the changes:**
- Stage the changes using:
```sh
git add placeholder.qmd
```
- Commit the changes with:
```sh
git commit -m "Add new café section to Rotterdam guide"
```

6. **Switch back to the default branch:**
- Switch to the main branch:
```sh
git switch main
```

7. **Merge the `feature` branch with the default branch:**
- Merge the `feature` branch:
```sh
git merge feature
```

8. **Delete the `feature` branch:**
- Delete the branch as it's no longer needed:
```sh
git branch -d feature
```

### Create and Resolve a Merge Conflict

1. **Create a merge conflict:**
- On the `feature` branch, add or change content in `placeholder.qmd`.
- Example change:
```markdown
## Best Spot for Breakfast in Hamburg
Café Paris: A beautiful café near the Rathaus, perfect for a luxurious breakfast.
```

- On the main branch, make conflicting changes to the same section:
```markdown
## Best Spot for Breakfast in Hamburg
Nord Coast Coffee Roastery: Known for its freshly roasted coffee and artisanal breakfast options.
```

2. **Attempt to merge the branches:**
- Try merging the `feature` branch into the main branch, resulting in a conflict:
```sh
git merge feature
```

3. **Resolve the merge conflict:**
- Open `placeholder.qmd` and manually edit the file to resolve the conflict:
```markdown
## Best Spot for Breakfast in Hamburg
Café Paris: A beautiful café near the Rathaus, perfect for a luxurious breakfast.
Nord Coast Coffee Roastery: Known for its freshly roasted coffee and artisanal breakfast options.
```

4. **Stage the resolved changes:**
- Stage the changes:
```sh
git add placeholder.qmd
```

5. **Commit the resolved changes:**
- Commit the resolved conflict:
```sh
git commit -m "Resolve merge conflict by including both café recommendations"
```

6. **Delete the `feature` branch:**
- Finally, delete the branch:
```sh
git branch -d feature
```
14 changes: 14 additions & 0 deletions exercises/_solutions-cli_cityguide.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
### Navigate the file system
1. Use `cd` to navigate
2. Use `pwd` to display the path of your chosen folder.

### Create files and folders

3. Use `mkdir` to create a new subfolder and name it `git-course`, within your chosen folder.
4. Use `cd` to navigate into your new subfolder
5. Use `pwd` to display the path of your chosen folder.

### Explore the File system

6. Use `cd`, `ls`, `ls -a` and `pwd` to explore your local file system

76 changes: 76 additions & 0 deletions exercises/_solutions-first-steps-git_cityguide.qmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
### Connect to GitHub

1. Generate a personal access token (PAT) on GitHub.

- Go to GitHub.
- Click on your profile picture in the upper-right corner and select Settings.
- In the left sidebar, click Developer settings.
- In the left sidebar, click Personal access tokens.
- Click Generate new token.
- Give your token a descriptive name.
- Select the scopes or permissions you'd like to grant this token. For uploading a repository, select the repo scope.
- Click Generate token.
- Copy the token and store it in a secure place. You won’t be able to see it again.

2. Use the PAT for GitHub authentication.

- When prompted for a username and password for GitHub operations (like git push), use your GitHub username as the username and the generated PAT as the password.

### "Download" the repository for this course

### Solution: "Download" the Repository for This Course

1. **Navigate into an appropriate place on your system:**
- Open your terminal or command line interface.
- Use the `cd` command to navigate to the directory where you want to download the repository. For example:
```sh
cd ~/Documents/Projects
```

2. **Go to GitHub and copy the URL of the course repository:**
- Open your web browser and go to the GitHub page of the course repository.
- Click on the "Code" button and copy the repository URL
(usually it will be something like `https://github.com/username/repository.git`).

3. **Use `git clone` to download the repository:**
- In your terminal, use the `git clone` command followed by the URL you copied. For example:
```sh
git clone https://github.com/username/repository.git
```
- This will download the entire repository into the directory you navigated to earlier.


### Add Content and Commit Changes

1. **Open the folder in RStudio as a new project**:
- Open RStudio.
- Click on `File` -> `New Project` -> `Existing Directory`.
- Navigate to the cloned repository folder and select it.
- Click `Create Project`.

2. **Open `placeholder.qmd`**:
- In the RStudio File Explorer, navigate to the cloned repository and open `placeholder.qmd`.

3. **Ask your partner for their favorite café in their city and write it down in `placeholder.qmd`**:
- Add the café name and a short description in `placeholder.qmd`.
- Save the file by clicking on `File` -> `Save` or pressing `Ctrl + S`.

4. **Stage the changes**:
- **Using RStudio**:
- In the RStudio Git pane, check the box next to `placeholder.qmd` to stage the changes.
- **Using the Command Line**:
- Run the command:
```sh
git add placeholder.qmd
```

5. **Commit the changes in `placeholder.qmd` with a descriptive commit message**:
- **Using RStudio**:
- Click on `Commit` in the Git pane.
- Enter a descriptive commit message, such as "Add favorite café in city X".
- Click `Commit` to finalize the commit.
- **Using the Command Line**:
- Run the command:
```sh
git commit -m "Add favorite café in city X"
```
Loading
Loading