In this video we're going to initialize our project as a git repository
git is a
really useful tool that allows you to keep track of all the changes that you
make to your project before you can start using git you need to initialize
your project so it sets up the git working files
you initialize the git
project by using the command line interface for git so if we open up our
terminal and then CD or change directory to our project folder and then we can
type git init to initialize our git repository
you know that the
repository has been initialized if you get this message saying initialized empty
git repository in and then the path of our project
once the git repository has
been initialized let's open up atom and if you still have
atom open from the previous videos then close it first because we need to reload
it completely in order to for it to detect that the projects changed to a
git repository
alright so now I'm just going to reopen
atom here and once atom is open I'm going to go file add project folder and I'm going
to add the project for our profiles REST API in our courses workspace
alright you
can tell that the project has been initialized as a git repository because
of this icon here is changed from the standard folder icon to this kind of
like a folder icon and this means that the project is now detected in atom as a
git project and you also have this hidden dot git directory here which will
contain all of the working snapshots that git stores as we make changes to
our project now this folder is completely managed by git so you should
never need to go into this folder or modify in any way it should happen
automatically by the git tool
ok now that we have initialized our project
let's go ahead and add some files to our git project I'm just going to expand this
window here and the first file that we're going to create is the readme file it's
best practice to create a readme file with any project that you create because
the purpose of the readme file is so that if somebody finds the project or if
you pick it up later on you may have forgotten what it was the readme file can
explain what it is and how to use it we're just going to create an empty read
me file by creating a new file and we'll call it readme dot MD
MD stands for markdown
and this is kind of the latest industry standard for writing documentation on
git projects
okay you can see that the new file was created and is highlighted
in green this means that it's a additional file to our project since we
last committed in git so since we've never done a git commit any file that we
add will automatically be green because it hasn't been added yet so Atom knows
that this files doesn't exist in our git project and we need to add it so I'm
going to show you how to add it in a bit but first let's populate the readme file
with just some basic things so I'm going to create a hash here and hash is the
basically the syntax for a heading in our readme file now I'm not going to go
into too much detail about how to write markdown in this video but I will put a
link in the resources of the video to a page where you can learn how to write
markdown files
alright so the first heading of our readme I'm going to put
profiles rest API and then below this I'm just going to put a description
profiles rest api course code
alright let's save that file and now let's
create the next file which is the git ignore file whenever you're committing
to a git project there are always some files that is best practice to
exclude from your git project these include things like local database files
and Python binary files that will be created automatically when we run our
project it's best practice to only commit the basic text-based source code
into our git project and the way you separate the code that should be
committed versus the code that is not going to be committed is you use what's
called a git ignore file
the git ignore file is simply a list of files that
tells git don't add any of these files or directories to our project when we do
git commit
okay so let's go ahead and create our new git ignore file so if we
type dot git ignore and I've created a I've pre created a git ignore file
specifically for this project and you can find that in the resources of the
video so if you click on that and then we'll just load up the browser here and
you can see that I have this git ignore file here so this is the contents of the
git ignore file that works for this project it's a standard git ignore file
for a Python and vagrant project and I'm just going to copy all of this and I'm
going to head over to Atom and I'm going to paste it in the git ignore file alright now
let's save that and you can see there's a whole list of files here and I got
these from this website called gitignore.io I'll also put this in the
link in the resources of the video as well but this is a website that allows
you to generate a git ignore file for a particular project and you can see here
that I'm generating it for a Python and a vagrant project and it pre-populates
with all of the things that are best to exclude from your git project for these
particular languages
okay now we have the git ignore file created let's create
the last file that we're going to do in this video and that is the license file
now because we're going to be pushing our project to github and it'll be
publicly accessible it's best practice to include a license with the project
and this is for two reasons one is to show or make it clear to others what
they're allowed to do with this code if they want to reuse it and the second is
to protect yourself so they can't sue you if anything goes wrong because you
basically say in the license that there's no warranty or liability
accepted for anything that happens with this project so let's create a new file
and let's call it license you can just call it a license it doesn't have to
have an extension on the end and then in the resources I've linked to the MIT
license now this is a permissive license that allows basically anyone to do
anything with this code since this is course code I'm happy for
anyone to take it and use it as they like so I'm just going to copy the contents
of this license here and then go back to the atom editor and paste it and then
just update the year to the current year so it's currently 2019 and where it says
full name I'm going to put my company name but feel free to use your own name if
you don't have a company
Alright so let's save this file and now we're ready
to make our first commit to our gt project
the way that you commit to a git
project is you use the terminal and the first thing you need to do is use the
git add command to add any new files which have been added to our project so
let's type git add dot this will add all of these green files to our project and
get them ready to be committed if you don't type git add then it doesn't
automatically add new files to our git project so you have to run this command
anytime that you've added or removed files from the project alright next
we're going to type git commit - am and what this does is it says git
commit and the a is for all and M is the message so we're going to put the
message in line here we're not going to use the vim editor that it uses by default
if you don't provide this m I prefer to write the commits in line because
it's just simpler that way so what you do here is you just describe the changes
that you've made to the project since the last commit
now since this is our
first commit I'm just going to type initial commit and hit enter
alright and now it has committed the files to our project that's how you
create a git repository and add files to it