Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
1f15db0
Create first set of screenshots for 03-create.md
dtwwwc1e Sep 12, 2024
49fd838
Amend open folder instructions in 03-create.md
dtwwwc1e Sep 13, 2024
bb76e01
Add directory screenshots
dtwwwc1e Sep 16, 2024
1b1f620
Rename 03-c-directory-show-hiddenn.JPG to 03-c-directory-empty-view-m…
dtwwwc1e Sep 16, 2024
028b104
Rename 03-c-directory-empty.JPG to 03-c-directory-show-hidden-items.JPG
dtwwwc1e Sep 16, 2024
5b0a9b9
Update show hidden items in folder
dtwwwc1e Sep 16, 2024
8a2a50e
Add images for changing branch name
dtwwwc1e Sep 20, 2024
a5751c7
Update 03-d-main to show button
dtwwwc1e Sep 20, 2024
a947b20
Amend section on change branch name and show status
dtwwwc1e Sep 20, 2024
ef17040
Add images for create dessert repository
dtwwwc1e Sep 20, 2024
279bad1
Amended section on nested repository
dtwwwc1e Sep 20, 2024
aa9d40b
Add screenshots first part of 04 episode
dtwwwc1e Oct 10, 2024
43e191a
Correct staging screenshots
dtwwwc1e Oct 10, 2024
097cd0f
Add missing screenshot on explorer menu
dtwwwc1e Oct 10, 2024
c377c03
Correct new file screenshot
dtwwwc1e Oct 10, 2024
c6ec068
Update file untracked screeshot
dtwwwc1e Oct 10, 2024
778308d
Update 04-changes to section Edit Text File
dtwwwc1e Oct 10, 2024
437b118
Correct file name 04-a7-new-file.JPG
dtwwwc1e Oct 11, 2024
a9dbb81
Correct two screenshots in creating file section
dtwwwc1e Oct 11, 2024
e7b89b1
Correct git status screenshots
dtwwwc1e Oct 11, 2024
7597386
Amended 04 episode, add text section
dtwwwc1e Oct 11, 2024
cdaaf18
Correct Source Control view screenshot
dtwwwc1e Oct 11, 2024
2a65463
Update 04-changes to staging
dtwwwc1e Oct 11, 2024
231e73f
Rename commit button image for clarity
dtwwwc1e Nov 1, 2024
cf37f9c
Add commit images
dtwwwc1e Nov 1, 2024
bfb8104
Add Git log images
dtwwwc1e Nov 1, 2024
ed97733
Add commit details image
dtwwwc1e Nov 1, 2024
3c66d6b
Amend from git commit to git log / graph
dtwwwc1e Nov 1, 2024
59e2042
Minor edits for typos and images
dtwwwc1e Nov 1, 2024
ce1cc5a
Add images for git change
dtwwwc1e Nov 4, 2024
9853cbe
Amend git changes section with screenshots
dtwwwc1e Nov 4, 2024
99bc621
Add images for second commit
dtwwwc1e Nov 19, 2024
4b9bb29
Update 04-changes.md to Let's watch as our changes...
dtwwwc1e Nov 19, 2024
7d2bd79
Add images for more staging example
dtwwwc1e Nov 19, 2024
792c867
Update 04-changes.md to third commit
dtwwwc1e Nov 19, 2024
61d143a
Add images for third commit
dtwwwc1e Nov 21, 2024
71509c2
Add git graph icon
dtwwwc1e Nov 21, 2024
9d08db3
Rename 04 image
dtwwwc1e Nov 21, 2024
eb9b0b5
Update 04 one image
dtwwwc1e Nov 21, 2024
5ae508f
Update 04-changes to word-based diffing
dtwwwc1e Nov 21, 2024
660b3ef
Add view changes icon
dtwwwc1e Nov 22, 2024
239dad1
Update 04-changes.md for consistency of content
dtwwwc1e Nov 22, 2024
739d7f5
Update 04-changes all sections except the last exercise "bio"
dtwwwc1e Nov 29, 2024
88ef7fa
Add 04 - missing images
dtwwwc1e Nov 29, 2024
6cc10ec
Update 04 for consistency of text
dtwwwc1e Nov 29, 2024
a906c62
Update 'bio' exercise and keypoints
dtwwwc1e Nov 29, 2024
95e0589
Add images for 04 bio exercise
dtwwwc1e Nov 29, 2024
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
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:

```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`:

<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.

<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.
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%>

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`:

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

```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`:

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%>

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.

::::::::::::::::::::::::::::::::::::::: 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`.

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

## 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
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.

```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.
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.
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.

::::::::::::::::::::::::::::::::::::::::::::::::::
Loading