2. Git Init
Initializing a Local Repository
We'll do some practice with Git by creating a dummy project. First of all,
as we've talked about, you should keep a folder in your home directory
called /code
(or something) where you store all your code.
From there, you'll have different folders for different projects. Go ahead
and create a /code
folder (if you don't already have one).
Now, open your command-line and navigate to your /code
folder
(or wherever you're going to keep track of your code). The command
cd
will change directories for you:
cd code
Now that you're inside this folder, we're going to create a new project by
creating a new folder. Let's call it git-fun
.
mkdir git-fun
As you can see, mkdir
will make a new directory. Now let's
view all the files/folders in our current directory:
ls
Or if you're using a windows machine:
dir
Now let's navigate into git-fun
with cd
:
cd git-fun
It's time to create a file. Let's start by merely creating an
index.html
file.
touch index.html
Or for windows users:
copy nul index.html
Now let's open this in VSCode:
code .
Perfect. Now we want to start tracking all of this with Git. To do that, use your command-line to write:
git init
As a response, you'll see (or something similar):
Initialized empty Git repository in /Users/aaronhayslip/code/project-shift/git-fun/.git/
Git has now implanted a hidden folder inside of this directory
(/git-fun
) called .git
. This is the mechanism
that will track changes in your files.
You can view this hidden folder in the command-line by writing:
ls -la