Hi, in this video it's time for us to put our code into a Git repository.
In this video, we're going to set up a new repository with our source code mostly from
the command line.
If you're already used to using git, this will be review.
In the next git video, we'll go over the development process.
And then we'll connect this together to automatically add Git versioning inside our microservice.
But we have to set things up first.
A best practice is to get all of this in place early in the development process.
We're using GitHub, because it's the one everyone is familiar with.
Feel free to use any other Git repository such as GitLab or Bitbucket.
This tutorial also assumes you already have Git installed on your machine.
Git is a version control system, that tracks the different versions of our source code.
Every time we make a change and save it to Git, a new version of our code is stored.
Not only can we get the most recent version of our code, we can also reference previous
versions.
This will be important for when we need to know what version of our code produced the
microservice in production.
Right now, we just need to move our code into Git.
Here's what we're going to do.
We'll create a repository on Github, initialize a repository on our machine, setup the ignore
file and readme, and check our code into GitHub.
Don't worry if that all didn't make sense.
We're going to cover each step in detail.
Let's get started.
Our first step is to go to Github.com.
Click on the Repositories tab and click on the New button.
You can also click on the plus in the upper right corner and select new repository.
This will take us to a page that looks like this.
We'll want to give the repository a name.
The description is a good idea, especially if we have many repositories.
We do have the choice of making it public or private.
If we're considering making it private, I'd recommend using GitLab.
They have free private repos.
Since we're going to bring in an existing repo, skip adding a readme.
We'll add that later.
We'll skip the gitignore and license for the same reasons.
Once we're done, we'll hit create repository.
We now have a repository in GitHub.
So let's go back to our machine and connect it with our code.
First we need to initialize a git repository on our machine.
We'll navigate to our code directory, and enter the following Git commands.
First we want to do git init.
This initializes our code directory as a git directory.
What it does is creates a directory inside our code directory with all the information
it needs to track our changes.
Next we want to link our repository to the one on GitHub.
We'll do that with the command git remote add origin https://github.com/deege/test.git
This tells git that there's a remote version of our code, and the URL tells Git where it
is.
Once we're done, we can verify the remote is added with the command git remote -v.
This will list all the remote repositories linked to our repository.
Now before we check in files, we want to let Git know which files are important.
We do this by telling Git to ignore some files by adding a .gitignore file.
The file just lists files and file expressions to ignore.
So we'll create a file, and then add the following to it.
Anything between hash marks are comments.
For now, we'll just make sure nothing in the compiled is added.
Next we want to create the README.
This file is named README.md.
The MD stands for markdown, and you can find many resources on formatting the document
using markdown online.
Check the transcript for links to learn the markdown syntax.
In this file we'll add some simple text for now.
And finally we'll add the code to our remote repository in GitHub.
We add it with the command
git add .
That adds everything.
Then we'll commit it with the following command.
git commit -m "first commit"
This command commits our changes to the local repository, and adds a message about what
we changed.
Usually you'll want to include more information, but since this is the first commit we'll just
say that.
Finally we want to push our changes into GitHub.
We'll do that with the command
git push origin master
And our code should be in Github.
We can refresh the repository and we should see our code.
So that's how we get our code into GitHub.
GitHub is free as long as your repository is open source and public.
If you need a private repository, you can pay GitHub for private repositories.
If you don't want to pay, Bitbucket is free for academics, and GitLab allows free private
repositories.
That might be the best option if you're indie and not an academic.
In the next tutorial, we'll want to go over how we track changes in our code.
Thanks for watching the video.
You can find the source code and the complete transcripts on DeegeU.com.
Next we'll take a look at our development process in Git.
If you like what you're seeing or have any questions, let me know in the comments or
on DeegeU.com!
See you in the next tutorial!