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

Update 03 create episode #5

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
142 changes: 60 additions & 82 deletions episodes/03-create.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,47 @@ we can start using it.

We will help Alfredo with his new project, create a repository with all his recipes.

First, let's create a new directory in the `Desktop` folder for our work and then change the current working directory to the newly created one:
First, let's create a new directory in the `Desktop` folder for our work:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
First, let's create a new directory in the `Desktop` folder for our work:
First, let's create a new `recipes` directory in the `Desktop` folder for our work:


```bash
$ cd ~/Desktop
$ mkdir recipes
$ cd recipes
```
<img src="fig/03-a-create-directory.JPG" alt="03-a-create-directory" width=50%>

We then open this newly created folder in VS Code by clicking `Open Folder`:

<img src="fig/03-a-directory-opened.JPG" alt="03-a-directory-opened" width=50%>

and then selecting the `recipes` folder:

<img src="fig/03-a-select-directory.JPG" alt="03-a-select-directory" width=50%>

Then we tell Git to make `recipes` a [repository](../learners/reference.md#repository)
\-- a place where Git can store versions of our files:
\-- a place where Git can store versions of our files. Click menu `View` and then `Source Control`:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
\-- a place where Git can store versions of our files. Click menu `View` and then `Source Control`:
\-- a place where Git can store versions of our files. Click the `Source Control` button <img src="https://www.svgrepo.com/show/361322/source-control.svg" atl="Source Control Button" width="30px"> on the left bar (third from the top, or through the `View` menu if the bar is hidden):


<img src="fig/03-b-source-control-menu.JPG" alt="03-b-source-control-menu" width=50%>

```bash
$ git init
```
Click `Initialize Repository`:

It is important to note that `git init` will create a repository that
<img src="fig/03-b-initialize-repository.JPG" alt="03-b-initialize-repository" width=50%>

and you will see `Source Control` which means the repository is created.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
and you will see `Source Control` which means the repository is created.
and you will see `Source Control` pannel which means the repository is created.


<img src="fig/03-b-source-control.JPG" alt="03-b-source-control" width=50%>


It is important to note that `Initialize Repository` will create a repository that
can include subdirectories and their files---there is no need to create
separate repositories nested within the `recipes` repository, whether
subdirectories are present from the beginning or added later. Also, note
that the creation of the `recipes` directory and its initialization as a
repository are completely separate processes.

If we use `ls` to show the directory's contents,
it appears that nothing has changed:
If we view the repository in its folder, it appears that nothing has changed since there is no visible content. To see what changed, click `View` in the folder:

```bash
$ ls
```
<img src="fig/03-c-directory-empty-view-menu.JPG" alt="03-c-directory-empty-view-menu" width=50%>

But if we add the `-a` flag to show everything,
we can see that Git has created a hidden directory within `recipes` called `.git`:
and choose `Show` and `hidden items`. We can see that Git has created a hidden directory within `recipes` called `.git`:

```bash
$ ls -a
```
<img src="fig/03-c-directory-show-hidden-items.JPG" alt="03-c-directory-show-hidden-items" width=50%>

```output
. .. .git
```

Git uses this special subdirectory to store all the information about the project,
including the tracked files and sub-directories located within the project's directory.
Expand All @@ -69,33 +71,24 @@ we will lose the project's history.

Next, we will change the default branch to be called `main`.
This might be the default branch depending on your settings and version
of git.
of git.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
of git.
of git.

See the [setup episode](02-setup.md#default-git-branch-naming) for more information on this change.

```bash
$ git checkout -b main
```
To see branch name, ensure that `Source Control Repositories` is selected. As shown below, the branch is called "project".

```output
Switched to a new branch 'main'
```
<img src="fig/03-d-source-control-repositories.JPG" alt="03-d-source-control-repositories" width=50%>
Comment on lines +77 to +79
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it called project? By default, on a new installed system is either main or mater. I'd suggest to change this bit into:

To see the branch name, you can either see it on the bottom left corner.

<img src="fig/todo/showing the bottom bar of the vs code window>

The source control repository panel is not required.


We can now start using one of the most important git commands, which is particularly helpful to beginners. `git status` tells us the status of our project, and better, a list of changes in the project and options on what to do with those changes. We can use it as often as we want, whenever we want to understand what is going on.
Under `Source Control Repositories`, click on the three dots of our repository `recipes`, and select `Rename Branch`:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Under `Source Control Repositories`, click on the three dots of our repository `recipes`, and select `Rename Branch`:
Under `Source Control` the three dots menu, navigate through `Branch` and select `Rename Branch`:


```bash
$ git status
```
<img src="fig/03-d-source-control-sub-menu.JPG" alt="03-d-source-control-sub-menu" width=50%>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update using the source control panel


```output
On branch main
<img src="fig/03-d-rename-branch.JPG" alt="03-d-rename-branch" width=50%>

No commits yet
Enter "main" and press Return to save. The branch is renamed to `main`:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Enter "main" and press Return to save. The branch is renamed to `main`:
Enter "main" and press <kbd>Return</kbd> to save. The branch is renamed to `main`:


nothing to commit (create/copy files and use "git add" to track)
```
<img src="fig/03-d-main.JPG" alt="03-d-main" width=50%>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show the bottom left corner. No need to change it from above, as by default it won't be required, so you can link to the same image.


If you are using a different version of `git`, the exact
wording of the output might be slightly different.
We can now start using one of the most important git commands, which is particularly helpful to beginners. In the screenshot above, in the `Source Control` window, is a blue button. It will show a different command depending on the status of our repository. Under this button we will find what changes have been made in the repository and the status of this change. The information here is updated as we make changes to our repository. We will see more examples of this later. For now, remember that this `Source Control` window tells us the status of our project, and better, a list of changes in the project and options on what to do with those changes. We can refer to it as often as we want, whenever we want to understand what is going on.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For version control purposes, it's better to keep multiple lines (one sentence per line) rather than a whole paragraph in a single line.

Suggested change
We can now start using one of the most important git commands, which is particularly helpful to beginners. In the screenshot above, in the `Source Control` window, is a blue button. It will show a different command depending on the status of our repository. Under this button we will find what changes have been made in the repository and the status of this change. The information here is updated as we make changes to our repository. We will see more examples of this later. For now, remember that this `Source Control` window tells us the status of our project, and better, a list of changes in the project and options on what to do with those changes. We can refer to it as often as we want, whenever we want to understand what is going on.
We can now start using one of the most important git commands,
which is particularly helpful to beginners.
In the screenshot below, in the `Source Control` window, is a blue button.
It will show a different command depending on the status of our repository.
Under this button we will find what changes have been made in the repository
and the status of this change.
The information here is updated as we make changes to our repository.
We will see more examples of this later.
For now, remember that this `Source Control` window tells us the status of our project,
and better, a list of changes in the project and options on what to do with those changes.
We can refer to it as often as we want, whenever we want to understand what is going on.

And add a new screenshot of the whole source control bar, that shows the whole left side of a vs code window, from the top menu till the bottom corner.


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

Expand All @@ -104,20 +97,23 @@ wording of the output might be slightly different.
Along with tracking information about recipes (the project we have already created),
Alfredo would also like to track information about desserts specifically.
Alfredo creates a `desserts` project inside his `recipes`
project with the following sequence of commands:
project. Is it a good idea to have a repository for tracking files stored in the `desserts` subdirectory?

To create the repository for `dessert`, Alfredo selects this folder in VSCode, as shown below:

```bash
$ cd ~/Desktop # return to Desktop directory
$ cd recipes # go into recipes directory, which is already a Git repository
$ ls -a # ensure the .git subdirectory is still present in the recipes directory
$ mkdir desserts # make a sub-directory recipes/desserts
$ cd desserts # go into desserts subdirectory
$ git init # make the desserts subdirectory a Git repository
$ ls -a # ensure the .git subdirectory is present indicating we have created a new Git repository
```
<img src="fig/03-e-select-dessert-folder.JPG" alt="03-e-select-dessert-folder" width=50%>

Is the `git init` command, run inside the `desserts` subdirectory, required for
tracking files stored in the `desserts` subdirectory?
However, VS Code tells Alfredo there is an error in one or two messages:

<img src="fig/03-e-warning-parent-repository-exists.JPG" alt="03-e-warning-parent-repository-exists" width=50%>

<img src="fig/03-e-parent-repository-button.JPG" alt="03-e-parent-repository-button" width=50%>

Alredo explores further using the `Open Repository` button and it looks like Alfredo cannot create this repository:

<img src="fig/03-e-parent-repository-open.JPG" alt="03-e-parent-repository-open" width=50%>

What should Alfredo do?

::::::::::::::: solution

Expand All @@ -133,25 +129,15 @@ Additionally, Git repositories can interfere with each other if they are "nested
the outer repository will try to version-control
the inner repository. Therefore, it's best to create each new Git
repository in a separate directory. To be sure that there is no conflicting
repository in the directory, check the output of `git status`. If it looks
like the following, you are good to go to create a new repository as shown
above:

```bash
$ git status
```

```output
fatal: Not a git repository (or any of the parent directories): .git
```
repository in the directory, check the output of `git status`.
Comment on lines 131 to +132
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't really work in here. There's a setting in VS Code, but we can show the message VS Code shows when trying to open a folder that belongs to a repository:
image
vs opening a folder without a parent repository:
image

Remade those in your theme to keep them consistent.


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

## Correcting `git init` Mistakes
## Correcting Initialize Repository Mistakes

Jimmy explains to Alfredo how a nested repository is redundant and may cause confusion
Alfredo has managed to create the `dessert` repository inside `recipes`. Jimmy explains to Alfredo how such a nested repository is redundant and may cause confusion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Alfredo has managed to create the `dessert` repository inside `recipes`. Jimmy explains to Alfredo how such a nested repository is redundant and may cause confusion
Alfredo has managed to create the `dessert` repository inside `recipes`.
Jimmy explains to Alfredo how such a nested repository is redundant and may cause confusion

down the road. Alfredo would like to go back to a single git repository. How can Alfredo undo
his last `git init` in the `desserts` subdirectory?
his last Initialize Repository in the `desserts` subdirectory?

::::::::::::::: solution

Expand All @@ -161,30 +147,22 @@ his last `git init` in the `desserts` subdirectory?

Removing files from a Git repository needs to be done with caution. But we have not learned
yet how to tell Git to track a particular file; we will learn this in the next episode. Files
that are not tracked by Git can easily be removed like any other "ordinary" files with
that are not tracked by Git can easily be removed like any other "ordinary" files by deleting them in VSCode Explorer.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
that are not tracked by Git can easily be removed like any other "ordinary" files by deleting them in VSCode Explorer.
that are not tracked by Git can easily be removed like any other "ordinary" files by deleting them in the system file browser.


```bash
$ rm filename
```

Similarly a directory can be removed using `rm -r dirname`.
Similarly a directory can be removed in the same way in Explorer.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Similarly a directory can be removed in the same way in Explorer.
Similarly a directory can be removed in the same way in VSCode `Explorer` panel.

If the files or folder being removed in this fashion are tracked by Git, then their removal
becomes another change that we will need to track, as we will see in the next episode.

### Solution

Git keeps all of its files in the `.git` directory.
To recover from this little mistake, Alfredo can remove the `.git`
folder in the desserts subdirectory by running the following command from inside the `recipes` directory:

```bash
$ rm -rf desserts/.git
```
folder in the desserts subdirectory by deleting the `.git` directory.

But be careful! Running this command in the wrong directory will remove
the entire Git history of a project you might want to keep.
In general, deleting files and directories using `rm` from the command line cannot be reversed.
Therefore, always check your current directory using the command `pwd`.
Further, although the deleted files and directories might be in the Recycle bin which can be recovered, we should not rely on this. Also the "Undo" command in VSCode does not always work to revert a delete command.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Further, although the deleted files and directories might be in the Recycle bin which can be recovered, we should not rely on this. Also the "Undo" command in VSCode does not always work to revert a delete command.
Further, although the deleted files and directories might be in the Recycle bin which can be recovered,
we should not rely on this.
Also the "Undo" command in VSCode does not always work to revert a deleted file or directory.

Into multiple lines. Also, does VSCode "sometimes" work to revert deleted files?

Therefore, always check your current directory.



Expand All @@ -194,7 +172,7 @@ Therefore, always check your current directory using the command `pwd`.

:::::::::::::::::::::::::::::::::::::::: keypoints

- `git init` initializes a repository.
- `Initialize Repository` sets up a new repository.
- Git stores all of its repository data in the `.git` directory.

::::::::::::::::::::::::::::::::::::::::::::::::::
Binary file added episodes/fig/03-a-create-directory.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added episodes/fig/03-a-directory-opened.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added episodes/fig/03-a-select-directory.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added episodes/fig/03-b-initialize-repository.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added episodes/fig/03-b-source-control-menu.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added episodes/fig/03-b-source-control.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added episodes/fig/03-c-directory-empty-view-menu.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added episodes/fig/03-c-directory-show-hidden-items.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added episodes/fig/03-d-main.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added episodes/fig/03-d-rename-branch.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added episodes/fig/03-d-source-control-repositories.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added episodes/fig/03-d-source-control-sub-menu.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added episodes/fig/03-e-parent-repository-button.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added episodes/fig/03-e-parent-repository-open.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added episodes/fig/03-e-select-dessert-folder.JPG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading