-
Notifications
You must be signed in to change notification settings - Fork 1
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
base: main
Are you sure you want to change the base?
Changes from all commits
1f15db0
49fd838
bb76e01
1b1f620
028b104
5b0a9b9
8a2a50e
a5751c7
a947b20
ef17040
279bad1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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`: | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
<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. | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
<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. | ||||||||||||||||||||||||||
|
@@ -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. | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
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`: | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
```bash | ||||||||||||||||||||||||||
$ git status | ||||||||||||||||||||||||||
``` | ||||||||||||||||||||||||||
<img src="fig/03-d-source-control-sub-menu.JPG" alt="03-d-source-control-sub-menu" width=50%> | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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`: | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
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%> | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
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 | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
@@ -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 | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
::::::::::::::::::::::::: | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
## 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 | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
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 | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
@@ -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. | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
```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. | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
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. | ||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Into multiple lines. Also, does VSCode "sometimes" work to revert deleted files? |
||||||||||||||||||||||||||
Therefore, always check your current directory. | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
@@ -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. | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
:::::::::::::::::::::::::::::::::::::::::::::::::: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.