Skip to content

Commit

Permalink
Update markdowns
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnikaLau committed Apr 5, 2024
1 parent fbf4fbc commit 12936ca
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 95 deletions.
10 changes: 5 additions & 5 deletions beginner/Markdowns/Exercise_1.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ This exercise consists of short descriptions of specific Git commands, followed
The following helper functions in the file *helpers.sh* are written by C2SM and are **NOT** **part of Git**. They will set up simple repositories for you that have a short Git history, so that you have something to work with.

For this exercise, we will use the following functions from this file:
* **init_exercise:** This will create the *beginners_git* directory in the parent directory of the *git-course* directory. It will also delete any old version of the *beginners_git* directory, so don't use the *beginners_git* directory to save any work.
* **reset:** This will delete the *beginners_git* directory and allows you a clean restart of the exercise in case you messed it up completely.
* `init_exercise`: This will create the *beginners_git* directory in the parent directory of the *git-course* directory. It will also delete any old version of the *beginners_git* directory, so don't use the *beginners_git* directory to save any work.
* `reset`: This will delete the *beginners_git* directory and allows you a clean restart of the exercise in case you messed it up completely.


## Remarks
Expand All @@ -36,7 +36,7 @@ If it returns something like `/home/juckerj`, change to the correct directory.
```bash
# check current directory with "pwd"

# go to folder of this exercise using "cd"
# in case you are in the wrong directory, navigate to Exercise_1 using "cd"

```

Expand Down Expand Up @@ -114,7 +114,7 @@ Initialized empty Git repository in <parent-dir-of-git-course>/beginners_git/git
### Make and track changes in files using `git add`, `git commit` and `git status`

In a next step you will add some files to your repository.
To do this, we will use the *echo* command in combination with the ">" operator to direct its
To do this, we will use the *echo* command in combination with the `>` operator to direct its
output to a file.


Expand Down Expand Up @@ -191,7 +191,7 @@ Your files are included in the Git repository.

### Know state of Git repository using `git diff` and `git log`
Right now we have two files in our Git repository.
Let's see what happens when we modify them. We will use the ">>" operator to append a new line of text to our files.
Let's see what happens when we modify them. We will use the `>>` operator to append a new line of text to our files.


```bash
Expand Down
20 changes: 10 additions & 10 deletions beginner/Markdowns/Exercise_2.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ Again, this exercise will consist of short descriptions of specific Git commands
The following helper functions in the file *helpers.sh* are written by C2SM and are **NOT** **part of Git**. They will set up simple repositories for you that have a short Git history, so that you have something to work with.

For this exercise, we will use the following functions from this file:
* **init_exercise:** This will create the *beginners_git* directory in the parent directory of the *git-course* directory. It will also delete any old version of the *beginners_git* directory, so don't use the *beginners_git* directory to save any work.
* **reset:** This will delete the *beginners_git* directory and allows you a clean restart of the exercise in case you messed it up completely.
* **init_simple_repo:** This will set up a Git repository containing a first version of *schedule_day1.txt* and *schedule_day2.txt* on the *main* branch.
* `init_exercise`: This will create the *beginners_git* directory in the parent directory of the *git-course* directory. It will also delete any old version of the *beginners_git* directory, so don't use the *beginners_git* directory to save any work.
* `reset`: This will delete the *beginners_git* directory and allows you a clean restart of the exercise in case you messed it up completely.
* `init_simple_repo`: This will set up a Git repository containing a first version of *schedule_day1.txt* and *schedule_day2.txt* on the *main* branch.

## Remarks
_**Reminder:** Any text enclosed in `<>` denotes a placeholder to be replaced with a specific string appropriate to your context, i.e. delete `<>` and replace it with the appropriate word._
Expand All @@ -27,7 +27,7 @@ _**Note:** Always run `git commit` and `git merge` with a Git message `-m <meani
```bash
# check current directory with "pwd"

# go to folder of this exercise using "cd"
# in case you are in the wrong directory, navigate to Exercise_2 using "cd"

```

Expand Down Expand Up @@ -66,8 +66,8 @@ init_simple_repo
```

In the output above we see two files:
* schedule_day1.txt
* schedule_day2.txt
* *schedule_day1.txt*
* *schedule_day2.txt*

Let's have a look at them using the `cat` command:

Expand Down Expand Up @@ -109,7 +109,7 @@ After saving, we run `git status` to see if Git has tracked our changes.

The output should look like:
```
On branch plan_day1
On branch planning_day1
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
Expand Down Expand Up @@ -151,7 +151,7 @@ Create a new branch for scheduling day 2 and extend the *schedule_day2.txt* file


```bash
# create a new branch for planning day 2
# create a new branch for the planning of day 2

```

Expand All @@ -174,8 +174,8 @@ The output should look like this:

```
main
plan_day1
* plan_day2
planning_day1
* planning_day2
```

Our Git repository now contains:
Expand Down
23 changes: 14 additions & 9 deletions beginner/Markdowns/Exercise_3.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
* Delete unused branches

## Structure
In this exercise we will continue working on the schedule for the two-day conference using *schedule_day1.txt* and *schedule_day2.txt* for each day's schedule. First, we need to revert the schedules back to a specific commit. Then we modify the same file, but on different branches. Finally, we merge all our changes back to the *main* branch.
In this exercise, we will continue working on the schedule for the two-day conference using *schedule_day1.txt* and *schedule_day2.txt* for each day's schedule. First, we need to revert the schedules back to a specific commit. Then we modify the same file, but on different branches. Finally, we merge all our changes back to the *main* branch.

Again, this exercise will consist of short descriptions of specific Git commands, followed by a hands-on part where you will be able to execute the corresponding Git commands.

## Helper Functions
The following helper functions in the file *helpers.sh* are written by C2SM and are **NOT** **part of Git**. They will set up simple repositories for you that have a short Git history, so that you have something to work with.

For this exercise, we will use the following functions from this file:
* **init_exercise:** This will create the *beginners_git* directory in the parent directory of the *git-course* directory. It will also delete any old version of the *beginners_git* directory, so don't use the *beginners_git* directory to save any work.
* **reset:** This will delete the *beginners_git* directory and allows you a clean restart of the exercise in case you messed it up completely.
* **init_repo:** This sets up a Git repository as in Exercise 2, but with more commits.
* `init_exercise`: This will create the *beginners_git* directory in the parent directory of the *git-course* directory. It will also delete any old version of the *beginners_git* directory, so don't use the *beginners_git* directory to save any work.
* `reset`: This will delete the *beginners_git* directory and allows you a clean restart of the exercise in case you messed it up completely.
* `init_repo`: This sets up a Git repository as in Exercise 2, but with more commits.

## Remarks
_**Reminder:** Any text enclosed in `<>` denotes a placeholder to be replaced with a specific string appropriate to your context, i.e. delete `<>` and replace it with the appropriate word._
Expand All @@ -29,7 +29,7 @@ _**Reminder:** Always run `git commit` and `git merge` with a git message `-m <m
```bash
# check current directory with "pwd"

# go to folder of this exercise using "cd"
# in case you are in the wrong directory, navigate to Exercise_3 using "cd"

```

Expand Down Expand Up @@ -83,14 +83,19 @@ To avoid doing the same work twice, we want to reuse the old schedules that we d

We can use `git restore` to get any version of a file along its Git history.

Just run `git restore --source=<specific_commit_hash> <your_schedule>`.
Just run `git restore -s <specific_commit_hash> <your_schedule>`.

**Note**:
For simplicity, we've used the `-s` option in the `git restore` command. Note that `-s` is a shorthand for `--source`, which you can also use interchangeably. The primary difference lies in the syntax: use `-s <commit_hash>` for a shorter command, or `--source=<commit_hash>` if you prefer a more explicit approach. Both options perform the same function: specifying the source from which to restore. Whether you prefer `-s` for brevity or `--source` for clarity is up to you.



Let's try it out for *schedule_day1.txt* first!


```bash
# restore the version of schedule_day1.txt before commit: "Change poster sessions to talks"
# "git restore --source=<commit_hash> <file_to_restore>"
# "git restore -s <commit_hash> <file_to_restore>"
# (Alternative - includes "git add": "git checkout <commit_hash> <file_to_restore>")

```
Expand Down Expand Up @@ -230,15 +235,15 @@ Let's put the pieces of the schedules together. For that we use the `git merge`
It allows us to merge files with different text from different branches.


To merge all modification from a branch inte the current branch, we type `git merge <branch-to-be-merged>`
To merge all modifications from a branch into the current branch, we type `git merge <branch-to-be-merged>`


```bash
# merge evening activity into main (make sure you are on the main branch for that)

```

Git just performed a so called **Fast-forward merge**. This means that there is a linear path
Git just performed a so-called **fast-forward merge**. This means that there is a linear path
between the two merged branches. See the slides for more detailed information about it.

**Most important:**
Expand Down
57 changes: 48 additions & 9 deletions beginner/Markdowns/Exercise_4.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@

## Objective
* Practice the typical Git workflow
* Understand the function of a *.gitignore* file, and learn the steps involved in creating and configuring it within a Git repository.

## Structure
In this exercise, we won't be learning any new Git commands. Rather, we will review all the commands and workflows we learned in the previous exercises. We will do this by working on the *conference_schedule.txt* document and simulating a possible workflow.
Since this is a review, there will be less explanation.

In this exercise, we won't be learning any new Git commands. Rather, we will review all the commands and workflows we learned in the previous exercises. We will do this by working on the *conference_schedule.txt* document and simulating a possible workflow. Since this is a review, there will be less explanation for that part of this exercise.

In addition to that, we will explore a crucial aspect of Git: the *.gitignore* file. We'll learn how to create and configure this file to manage the files that Git should ignore, enhancing our typical workflow.



## Helper Functions
The following helper functions in the file *helpers.sh* are written by C2SM and are **NOT** **part of Git**. They will set up simple repositories for you that have a short Git history, so that you have something to work with.

For this exercise, we will use the following functions from this file:
* **init_exercise:** This will create the *beginners_git* directory in the parent directory of the *git-course* directory. It will also delete any old version of the *beginners_git* directory, so don't use the *beginners_git* directory to save any work.
* **reset:** This will delete the *beginners_git* directory and allows you a clean restart of the exercise in case you messed it up completely.
* **init_repo_empty_schedule:** This will create the directory `conference_planning` and a file `conference_schedule.txt` with an empty schedule.
* `init_exercise`: This will create the *beginners_git* directory in the parent directory of the *git-course* directory. It will also delete any old version of the *beginners_git* directory, so don't use the *beginners_git* directory to save any work.
* `reset`: This will delete the *beginners_git* directory and allows you a clean restart of the exercise in case you messed it up completely.
* `init_repo_empty_schedule`: This will create the directory *conference_planning* and a file *conference_schedule.txt* with an empty schedule.

## Remarks
_**Reminder:** Any text enclosed in `<>` denotes a placeholder to be replaced with a specific string appropriate to your context, i.e. delete `<>` and replace it with the appropriate word._
Expand All @@ -26,7 +31,7 @@ _**Reminder:** Always run `git commit` and `git merge` with a git message `-m <m
```bash
# check current directory with "pwd"

# go to folder of this exercise using "cd"
# in case you are in the wrong directory, navigate to Exercise_4 using "cd"

```

Expand Down Expand Up @@ -76,6 +81,42 @@ init_repo_empty_schedule

```

### Understanding *.gitignore*

The *.gitignore* file is an essential and commonly used feature in Git. It specifies intentionally untracked files that Git should ignore. It's particularly useful for excluding files generated during execution or build processes—like log files, compiled code, or local configuration files—that don't need to be shared within the repository. Creating a *.gitignore* file and listing the file patterns to exclude achieves this.

**Typical Ingredients of *.gitignore*:**

Once your *.gitignore* is created, you can specify:

- **Patterns**: Direct patterns such as *my_file_to_ignore.txt* to exclude specific files or *my_directory_to_ignore/* to exclude specific directories. For example, *.ipynb_checkpoints/* is often added to the *.gitignore* when working with Jupyter Notebooks to ignore checkpoint folders created during development.
- **Wildcards**: Broad patterns like `*.log` to exclude all log files created across the project.
- **Exceptions**: If you've used a wildcard but want to track specific files, precede the exception with `!`. For instance, *!important_log.log* ensures this file is tracked despite the `*.log` exclusion.

Remember, the *.gitignore* file should be committed into your repository, so it is shared with other developers, ensuring that everyone working on the project is ignoring the same files.

**Practical Application:**

Now that you have seen and understood the concept of the *.gitignore* file, you can proceed with your exercises. At a certain point, after you run `git status`, you might notice a file named *.ipynb_checkpoints*. This is created by Jupyter Notebooks to save checkpoint files and it's exactly the type of content we aim to exclude from our Git repository, as it is specific to your local Jupyter Notebook environment. It thus presents a perfect opportunity to apply what you've just learned. Follow these steps to create a *.gitignore* and specify the patterns. Remember to add and commit your *.gitignore* after creating it.




```bash
# Create `.gitignore` and add the `.ipynb_checkpoints pattern` (Note: make sure you are in the conference_planning directory when running the following command)
echo ".ipynb_checkpoints/" >> .gitignore

```


```bash
# Add and commit your .gitignore


```

### Go on with your Exercise

Add events to the schedule.

Remember to make any changes to the schedule directly in Jupyter Notebooks:
Expand Down Expand Up @@ -185,7 +226,6 @@ We want to plan an evening activity but are not sure what it will be. Therefore,

# create new branch and add an evening activity


```

Add an evening activity and commit the changes. Don't forget to reload your file before changing!
Expand All @@ -205,7 +245,6 @@ Switch to branch *main* and create another branch on top of it, to add an altern

# create new branch and add another evening activity


```


Expand Down Expand Up @@ -245,7 +284,7 @@ Therefore merge the branch *alternative_talk* into *main*.


```bash
# follow good practice and delete the merge branch
# follow good practice and delete the merged branch

```

Expand Down
25 changes: 5 additions & 20 deletions beginner/Markdowns/Exercise_5.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ In this exercise we will start to learn about working with remote repositories.
The following helper functions in the file *helpers.sh* are written by C2SM and are **NOT** **part of Git**. They will set up simple repositories for you that have a short Git history, so that you have something to work with.

For this exercise, we will use the following functions from this file:
* **init_exercise:** This will create the *beginners_git* directory in the parent directory of the *git-course* directory. It will also delete any old version of the *beginners_git* directory, so don't use the *beginners_git* directory to save any work.
* **reset:** This will delete the *beginners_git* directory and allows you a clean restart of the exercise in case you messed it up completely.
* **init_simple_repo_remote:** This will create the same simple repository as before, along with a second repository to be used as a remote.
* `init_exercise`: This will create the *beginners_git* directory in the parent directory of the *git-course* directory. It will also delete any old version of the *beginners_git* directory, so don't use the *beginners_git* directory to save any work.
* `reset`: This will delete the *beginners_git* directory and allows you a clean restart of the exercise in case you messed it up completely.
* `init_simple_repo_remote`: This will create the same simple repository as before, along with a second repository to be used as a remote.

## Remarks
_**Reminder:** Any text enclosed in `<>` denotes a placeholder to be replaced with a specific string appropriate to your context, i.e. delete `<>` and replace it with the appropriate word._
Expand All @@ -27,7 +27,7 @@ _**Reminder:** Always run `git commit` and `git merge` with a git message `-m <m
```bash
# check current directory with "pwd"

# go to folder of this exercise using "cd"
# in case you are in the wrong directory, navigate to Exercise_5 using "cd"

```

Expand Down Expand Up @@ -186,19 +186,4 @@ To ../conference_planning_remote
1dacf13..80e64e8 updated_schedules -> updated_schedules
```

Now go to the folder *../conference_planning_remote* and check if you can see your changes in *schedule_day1.txt*.
Why can you not see them? (Think before you read the solution!)

**Solution**: In the remote repository you are still on the *main* branch. To change this, use the [Unix command](../Unix_Commands.ipynb) `cd` to navigate to *../conference_planning_remote* and switch to the *updated_schedules* branch. Can you now see your changes?


```bash
# Navigate to the remote repository

```


```bash
# Switch to the "updated_schedule" branch on the remote repository

```
**Congrats, you now also know the most essential Git commands for the _remote_ use of Git.**
Loading

0 comments on commit 12936ca

Please sign in to comment.