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

Move branches to the morning git section #73

Merged
merged 3 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ vendor/
.docker-vendor/
Gemfile.lock
.*history

.vscode
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ episodes:
- 01-basics.md
- 02-setup.md
- 03-create.md
- 09-branches.md
- 04-changes.md
- 05-history.md
- 06-reverting-changes.md
- 06-ignore.md
- Break.md
- 07-github.md
- 08-github-interface.md
- 09-branches.md
- 10-pull-requests.md
- End.md
- 10-open.md
Expand Down
59 changes: 59 additions & 0 deletions episodes/03-create.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,65 @@ $ fcm info
If you are using a different version of `git`, the exact
wording of the output might be slightly different.

## Initial Commit

As soon as you initialise your repository
you should make an initial commit.
All repositories should have a `README` file
which outlines the purpose of the repository
and other useful information.
For now we will create the file with just
the repository name, **Weather** as the title:

```bash
$ echo "# Weather" > README.md
$ cat README.md
```

```output
# Weather
```

Now add and commit the `README.md` file
using the `git add` and `git commit` commands:

```bash
$ git add README.md
$ git commit -m "Initial commit"
```

```output
[main (root-commit) 6f12a47] Initial commit
1 file changed, 1 insertion(+)
create mode 100644 README.md
```

You've just added your first file to be version controlled with Git!
This first commit is the special **root-commit**.
It is the start of your version control history and
like all commits has been given a unique alphanumeric hash (`6f12a47`).
In the next few episodes you will explore
tracking changes with `git add` and `git commit` in detail,
and learn how to inspect your repositories history.

::: callout

### README Files

All repositories should have a `README` file.
The `README` file describes what is in your repository.
The [makeareadme](https://www.makeareadme.com/) website is a great
resource for `README` templates and inspiration.

The `README.md` file we added is a [Markdown](https://www.markdownguide.org/basic-syntax/)
file.
Markdown is a simple markup language and
GitHub can render Markdown files natively.
The GitHub documentation pages on [Writing on GitHub](https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax)
have more info on writing in Markdown for GitHub.

:::

::::::::::::::::::::::::::::::::::::::: challenge

## Places to Create Git Repositories
Expand Down
121 changes: 81 additions & 40 deletions episodes/04-changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,14 @@ exercises: 0

::::::::::::::::::::::::::::::::::::::::::::::::::

::: caution

### Committing to Main

In this lesson you will be making changes on `main`.
The `main` branch normally contains stable production code and
should **NEVER** be committed to directly.
In the later GitHub and Branches episodes you will learn
a basic workflow to ensure you never commit to main;
and learn what to do when you accidentally commit to main.

:::

First let's make sure we're still in the right directory.
You should be in the `weather` directory.
First let's make sure we're still on the right branch.
You should be on the `forecast` branch:

```bash
$ cd ~/Desktop/weather
$ git switch forecast
```

Let's create a file called `forecast.md` that contains the basic structure to
have a recipe.
Let's create a file called `forecast.md` that contains a basic weather forecast.
We'll use `nano` to edit the file;
you can use whatever editor you like.
In particular, this does not have to be the `core.editor` you set globally earlier. But remember, the steps to create create or edit a new file will depend on the editor you choose (it might not be nano). For a refresher on text editors, check out ["Which Editor?"](https://swcarpentry.github.io/shell-novice/03-create.html#which-editor) in [The Unix Shell](https://swcarpentry.github.io/shell-novice/) lesson.
Expand All @@ -54,7 +40,9 @@ Type the text below into the `forecast.md` file:

```output
# Forecast

## Today

Cloudy with a chance of pizza.
```

Expand All @@ -77,7 +65,9 @@ $ cat forecast.md

```output
# Forecast

## Today

Cloudy with a chance of pizza.
```

Expand All @@ -89,7 +79,7 @@ $ git status
```

```output
On branch main
On branch forecast

No commits yet

Expand All @@ -116,15 +106,14 @@ $ git status
```

```output
On branch main
On branch forecast

No commits yet

Changes to be committed:
(use "git rm --cached <file>..." to unstage)

new file: forecast.md

```

Git now knows that it's supposed to keep track of `forecast.md`,
Expand All @@ -137,8 +126,8 @@ $ git commit -m "Create a md file with the forecast"
```

```output
[main (root-commit) f22b25e] Create a md file with the forecast
1 file changed, 3 insertions(+)
[forecast f22b25e] Create a md file with the forecast
1 file changed, 5 insertions(+)
create mode 100644 forecast.md
```

Expand Down Expand Up @@ -192,14 +181,24 @@ $ fcm commit

:::

Our repository now looks like this:

```mermaid
gitGraph
accDescr {A git graph showing the root-commit on the main branch and a new forecast branch, branching off the root-commit, with one commit.}
commit id: 'Initial commit'
branch forecast
commit id: 'Create a md file with the forecast'
```

If we run `git status` now:

```bash
$ git status
```

```output
On branch main
On branch forecast
nothing to commit, working tree clean
```

Expand All @@ -209,7 +208,8 @@ it tells us everything is up to date.

## Where Are My Changes?

If we run `ls` at this point, we will still see just one file called `forecast.md`.
If we run `ls` at this point, we will still see just our two files,
`README.md` and `forecast.md`.
That's because Git saves information about files' history
in the special `.git` directory mentioned earlier
so that our filesystem doesn't become cluttered
Expand All @@ -229,9 +229,13 @@ $ cat forecast.md

```output
# Forecast

## Today

Cloudy with a chance of pizza.

## Tomorrow

Morning rainbows followed by light showers.
```

Expand All @@ -243,7 +247,7 @@ $ git status
```

```output
On branch main
On branch forecast
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 @@ -273,11 +277,13 @@ diff --git a/forecast.md b/forecast.md
index df0654a..315bf3a 100644
--- a/forecast.md
+++ b/forecast.md
@@ -1,3 +1,5 @@
# Forecast
@@ -3,3 +3,7 @@
## Today

Cloudy with a chance of pizza.
+
+## Tomorrow
+
+Morning rainbows followed by light showers.
```

Expand Down Expand Up @@ -329,7 +335,7 @@ $ git commit -m "Add tomorrows forecast to forecast.md"
```

```output
On branch main
On branch forecast
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 All @@ -349,8 +355,8 @@ $ git commit -m "Add tomorrows forecast to forecast.md"
```

```output
[main 34961b1] Add tomorrows forecast to forecast.md
1 file changed, 2 insertions(+)
[forecast 34961b1] Add tomorrows forecast to forecast.md
1 file changed, 4 insertions(+)
```

Git insists that we add files to the set we want to commit
Expand Down Expand Up @@ -418,6 +424,17 @@ $ fcm commit

:::

Our repository now looks like this:

```mermaid
gitGraph
accDescr {A git graph showing the root-commit on the main branch and a new forecast branch, branching off the root-commit, with two commits.}
commit id: 'Initial commit'
branch forecast
commit id: 'Create a md file with the forecast'
commit id: 'Add tomorrows forecast to forecast.md'
```

Let's watch as our changes to a file move from our editor
to the staging area
and into long-term storage.
Expand All @@ -431,9 +448,13 @@ $ cat forecast.md

```output
# Forecast

## Today

Cloudy with a chance of Sun.

## Tomorrow

Morning rainbows followed by light showers.
```

Expand All @@ -446,13 +467,15 @@ diff --git a/forecast.md b/forecast.md
index 315bf3a..b36abfd 100644
--- a/forecast.md
+++ b/forecast.md
@@ -1,5 +1,5 @@
# Forecast
@@ -2,7 +2,7 @@

## Today

-Cloudy with a chance of pizza.
+Cloudy with a chance of Sun.

## Tomorrow
Morning rainbows followed by light showers.

```

So far, so good:
Expand Down Expand Up @@ -481,13 +504,15 @@ diff --git a/forecast.md b/forecast.md
index 315bf3a..b36abfd 100644
--- a/forecast.md
+++ b/forecast.md
@@ -1,5 +1,5 @@
# Forecast
@@ -2,7 +2,7 @@

## Today

-Cloudy with a chance of pizza.
+Cloudy with a chance of Sun.

## Tomorrow
Morning rainbows followed by light showers.

```

it shows us the difference between
Expand All @@ -500,7 +525,7 @@ $ git commit -m "Modify the forecast to add a chance of Sun"
```

```output
[main 005937f] Modify the forecast to add a chance of Sun
[forecast 005937f] Modify the forecast to add a chance of Sun
1 file changed, 1 insertion(+), 1 deletion(-)
```

Expand All @@ -511,10 +536,22 @@ $ git status
```

```output
On branch main
On branch forecast
nothing to commit, working tree clean
```

Our repository now looks like this:

```mermaid
gitGraph
accDescr {A git graph showing the root-commit on the main branch and a new forecast branch, branching off the root-commit, with three commits.}
commit id: 'Initial commit'
branch forecast
commit id: 'Create a md file with the forecast'
commit id: 'Add tomorrows forecast to forecast.md'
commit id: 'Modify the forecast to add a chance of Sun'
```

::::::::::::::::::::::::::::::::::::::::: callout

## Word-based diffing
Expand Down Expand Up @@ -669,10 +706,14 @@ $ cat forecast.md

```output
# Forecast

## Today

Cloudy with a chance of sun.
Mild temperatures around 16 °C.

## Tomorrow

Morning rainbows followed by light showers.
```

Expand Down Expand Up @@ -710,7 +751,7 @@ $ git commit -m "Add in the temperature to the forecast and create the weather a
```

```output
[main cc127c2]Add in the temperature to the forecast and create the weather atlas file
[forecast cc127c2] Add in the temperature to the forecast and create the weather atlas file
2 files changed, 6 insertions(+)
create mode 100644 atlas.md
```
Expand Down
Loading