1. Creating repos
Let's start working with Git!
2. Mental health in tech project
Throughout the course, we'll work on a project about mental health in tech. The files and directories are shown here.
To use Git for version control in our project, we first need to create a Git repository, often referred to as a repo.
3. What is a Git repo?
A repo is a directory consisting of two parts - the first is the files and sub-directories that we create and edit. In this case a file called funding.doc, a report in markdown file format, and a sub-directory called data.
4. What is a Git repo?
The second part is the extra information that Git records about the project's history.
The combination of these two things is called a repository.
Git stores all of its extra information in a directory called dot-git, located in the repo's main directory.
Git expects this information to be laid out in a particular way, so we should not edit or delete dot-git.
5. Why make a repo?
There are many benefits to creating a Git repo, including the ability to systematically track the versions of files, to revert to previous versions, and to compare versions at different points in time.
If we host our repo in the cloud, then it also enables easy collaboration with colleagues!
6. Creating a new repo
To create a new Git repo for our project, we use the git init command in the terminal, followed by the name of our project, mental-health-workspace.
When we run the git init command with the name we provided for the repo, Git creates a new repo within the directory we ran the command from.
We can use cd to change into this new repo.
We can check that the Git repo has been initialized correctly by running the git status command.
Success! The output confirms we have a Git repo, and suggests that once we've created files we can use the git add command to track them using Git.
7. Converting a project into a repo
Now we know how to create a Git repo from scratch, let's look at how to convert an existing project into a repo.
Let's say we started working on the mental health in tech project without first creating a new Git repo. We can convert the existing directory to a Git repo by executing git init without providing a directory name.
We run the command from our project directory. The output confirms that an empty repo has been created and provides the location.
8. What is being tracked?
Something interesting happens if we check the status of the repo.
We can see Git has immediately recognized that there are modified files not being tracked by Git, in this case, the report-dot-md file and files within the data subdirectory. The output encourages us to start tracking these files using Git! We'll discuss how to do this in the next video.
9. Nested repositories
One word of caution when creating Git repos.
Unless we are working on a very complex project, we should generally avoid creating a Git repo inside another Git repo, also known as nested repos.
If we do this, there will be two dot-git directories. Unfortunately, as we try to make commits, Git will get confused about which directory it needs to update.
10. Let's practice!
Time to make our own Git repos!