diff --git a/_episodes/03-create.md b/_episodes/03-create.md index 253013d88f..f63594772b 100644 --- a/_episodes/03-create.md +++ b/_episodes/03-create.md @@ -3,13 +3,16 @@ title: Creating a Repository teaching: 10 exercises: 0 questions: -- "Where does Git store information?" +- "How do I start a Git-tracked project?" +- "Where does Git store its information?" objectives: - "Create a local Git repository." - "Describe the purpose of the `.git` directory." keypoints: -- "`git init` initializes a repository." - "Git stores all of its repository data in the `.git` directory." +- "`git init` initializes a repository." +- "Git repositories shall not be nested." +- "`git status` checks the status of your project." --- Once Git is configured, @@ -44,21 +47,36 @@ $ cd planets {: .language-bash} Then we tell Git to make `planets` a [repository]({{ page.root }}{% link reference.md %}#repository) --- a place where Git can store versions of our files: +-- a place where Git can store versions of our files. +It is good practice to first check if this is a good place to do so: +a new repository shall not be nested in another repository placed higher up the directory hierarchy. +This is because a Git repository takes care of files in its subdirectories, too, +whether they are present from the beginning or added later. +We'll use a command that normally checks the status of a repository: ~~~ -$ git init +$ git status ~~~ {: .language-bash} -It is important to note that `git init` will create a repository that -includes subdirectories and their files---there is no need to create -separate repositories nested within the `planets` repository, whether -subdirectories are present from the beginning or added later. Also, note -that the creation of the `planets` directory and its initialization as a -repository are completely separate processes. +If we are outside of a repository (which is the expected outcome at this point), we get an error message: +~~~ +fatal: not a git repository (or any of the parent directories): .git +~~~ +{: .output} + +Later you'll see the output you'd get if you _were_ within an existing repository. +If that is your case, do not proceed creating a new repository. +Rather, investigate the situation. You may have placed your directory in a wrong location or you may be fine using the pre-existing repo. + +Assuming we are not within a repository yet, we can create one by the command: +~~~ +$ git init +~~~ +{: .language-bash} +What happened? If we use `ls` to show the directory's contents, it appears that nothing has changed: @@ -74,7 +92,6 @@ we can see that Git has created a hidden directory within `planets` called `.git $ ls -a ~~~ {: .language-bash} - ~~~ . .. .git ~~~ @@ -82,8 +99,25 @@ $ ls -a Git uses this special subdirectory to store all the information about the project, including all files and sub-directories located within the project's directory. -If we ever delete the `.git` subdirectory, -we will lose the project's history. +Should we accidentally delete it, we would lose the project's history. + +> ## What's inside the `.git` Sub-Directory? +> +> > ## Solution +> > Let's look inside the sub-directory: +> > +> > ~~~ +> > $ ls -a .git +> > ~~~ +> > {: .language-bash} +> > ~~~ +> > . .. HEAD config description hooks info objects refs +> > ~~~ +> > {: .output} +> > +> > All these files and directories are internal to Git and you should avoid changing them manually. +> {: .solution} +{: .challenge} Next, we will change the default branch to be called `main`. This might be the default branch depending on your settings and version @@ -99,7 +133,6 @@ Switched to a new branch 'main' ~~~ {: .output} - We can check that everything is set up correctly by asking Git to tell us the status of our project: @@ -116,8 +149,8 @@ nothing to commit (create/copy files and use "git add" to track) ~~~ {: .output} -If you are using a different version of `git`, the exact -wording of the output might be slightly different. +Note that for your version of `git` +the exact wording of the output might be slightly different. > ## Places to Create Git Repositories > @@ -129,11 +162,12 @@ wording of the output might be slightly different. > ~~~ > $ cd ~/Desktop # return to Desktop directory > $ cd planets # go into planets directory, which is already a Git repository -> $ ls -a # ensure the .git subdirectory is still present in the planets directory -> $ mkdir moons # make a subdirectory planets/moons -> $ cd moons # go into moons subdirectory -> $ git init # make the moons subdirectory a Git repository -> $ ls -a # ensure the .git subdirectory is present indicating we have created a new Git repository +> $ ls -a # ensure the .git sub-directory is still present in the planets directory +> $ mkdir moons # make a sub-directory planets/moons +> $ cd moons # go into moons sub-directory +> $ git status # ignore the fact that a Git repository already exists +> $ git init # make the moons sub-directory a Git repository +> $ ls -a # ensure the .git sub-directory is present indicating we have created a new Git repository > ~~~ > {: .language-bash} > @@ -150,20 +184,8 @@ wording of the output might be slightly different. > > > > 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: -> > -> > ~~~ -> > $ git status -> > ~~~ -> > {: .language-bash} -> > ~~~ -> > fatal: Not a git repository (or any of the parent directories): .git -> > ~~~ -> > {: .output} +> > the inner repository. +> > Therefore, do not skip the `git status` before running `git init`. > {: .solution} {: .challenge} > ## Correcting `git init` Mistakes @@ -189,7 +211,7 @@ wording of the output might be slightly different. > > ### Solution > > Git keeps all of its files in the `.git` directory. > > To recover from this little mistake, Dracula can just remove the `.git` -> > folder in the moons subdirectory by running the following command from inside the `planets` directory: +> > folder in the `moons` subdirectory by running the following command from inside the `planets` directory: > > > > ~~~ > > $ rm -rf moons/.git @@ -198,6 +220,7 @@ wording of the output might be slightly different. > > > > But be careful! Running this command in the wrong directory will remove > > the entire Git history of a project you might want to keep. -> > Therefore, always check your current directory using the command `pwd`. +> > Therefore, always check your current directory using the command `pwd` +> > and start the path to be deleted with the name of the subdirectory that contains the superfluous `.git`. > {: .solution} {: .challenge} diff --git a/_episodes/04-changes.md b/_episodes/04-changes.md index 3e16e371ad..e5f24c7f1a 100644 --- a/_episodes/04-changes.md +++ b/_episodes/04-changes.md @@ -11,7 +11,6 @@ objectives: - "Explain where information is stored at each stage of that cycle." - "Distinguish between descriptive and non-descriptive commit messages." keypoints: -- "`git status` shows the status of a repository." - "Files can be stored in a project's working directory (which users see), the staging area (where the next commit is being built up) and the local repository (where commits are permanently recorded)." - "`git add` puts files in the staging area." - "`git commit` saves the staged content as a new commit in the local repository."