Hey everyone, I'm Chris from Codecademy and
in this video we'll be talking about the power of Git and GitHub, and we'll see some examples of them being used in projects. So what is Git? Git is what we call a version control system, which allows you to track and manage changes to all types of files. It's primarily used for allowing groups of developers to work collaboratively on large software projects but it can also be used by small teams or even solo developers. This is accomplished by managing
the evolution of a set of files. Instead of managing each file individually and
sharing it manually with your team, you can use a repository which contains a collection of files and version information for a project. This repository tracks all changes made to the files building history over time. I'll use Git. Git is all about efficiency. One of the biggest advantages of Git is its branching capabilities. A branch is a way to keep a new feature or modification separate from the main project. It contains a different version of the files, which include any changes made after it was created from the project code. As soon as a repository is created, a main branch is generated. From there, one can work on code and track their work with commits. However, another member can also branch out from the specific point in the repositories history and work on their own code. This leaves the main project intact and isolated
from any experimental code that someone's working on. When you use Git and GitHub together, you gain access to a whole array of collaboration abilities by being able to put code up for review and even adding in automated testing. Git is not only great at managing different workspaces for team members but it's also very efficient for reviewing completed code. Once code is ready for review, a user can
create what's called a pull request. The pull request is essentially a dedicated forum for discussing
proposed changes in a soon-to-be merged branch. Not only does this make it easier for a project leads to keep track of changes but it also lets developers initiate discussions around the work before integrating it with the rest of the code base. Now what about GitHub? If you've heard about Git before, then you likely also heard about GitHub. GitHub is a website and cloud-based service that hosts Git repositories. While Git is a command line tool, GitHub provides a web-based graphical interface with many of its own added features for easier navigation and collaboration with projects. Now let's take a look at how Git and
GitHub can be used within a project. Let's start by looking at an example of a small Python project. We could be invited to work on this project by other team members who could have been linked to this project online or we could have even started this on our own. In any case, once we're on the GitHub page for the project, if we click on code and copy the cloning link. When installing Git, depending on the operating system, you could access it directly from the terminal or command prompt but in this case, I'm going to use the Git Bash application, which came with it. Now to actually have a code from the repository on our system, we'll need to navigate to a location where we want the repository to be cloned to using a combination of LS to list the directories and CD to change directories. Then we'll use the command Git clone and the link we copied. So use CD documents and then LS to view the directors here. And I'll change directories, again, into projects. Now I'll use git clone and the link we copied and hit enter. At this point, it may ask you to log in but once the command completes, it will have a new directory in the system
containing the contents of the repository. So we can use LS and see that Git example
exists, and we'll change directories into that. You can see the files within Git example, which right now is message.pi Now we could directly modify the files and
push changes to the repository but that's a bad practice, especially if other people are working on it at the same time. To avoid this, let's create a new branch. The command Git checkout dash b in the branch name creates a new branch and switches to it at the same time. So let's do that. Git checkout dash b and we'll call it print changes. Now that we're in the new branch, let's make a change to the message Python file. I'll use the nano editor and add in another print statement but you don't have to use the terminal for that, and you can edit it in any other program or IDE. So I'll use nano message.com and I'll add in another print statement. And let's also add a file to the repository. To do this we first need to create a new file in the same directory as our cloned repository. So I'll use Nano for that, as well. And we can use LS to check that we have two files here. Now to add in the new file to the repository and to add in the changes that we made to message.pi We can either use the commands Git add and the file name for each file or we can use Git add in the period character to add in all of the new files and changes. Now to confirm that the changes have been made to a branch and that the new file was added, we can use the command git status. And this will show that we've modified message.pi ,
that we've created the new file new underscorefile.pi , and they're ready to be committed. Let's save all these changes to our local branch using git commit, and we can provide a message describing the changes using dash m and the message that we want. So Git permit dash m, and let's say added a new print statement to message.py , created new_ file.py and hit enter. And here it may ask for some credentials, which you can add in using the command (inaudible), otherwise it will say that it committed successfully. Finally, now we've committed our changes, let's push the new branch to the repository and take a look at it on GitHub. The command for pushing a new branch is git push dash dash set dash upstream origin and our branch name, so print changes. And here it will ask you to sign into GitHub. And once you sign in, it will complete the command, and it will push the new branch to the remote repository. Now, let's take a look at our new branch and see how to create a pull request for it in GitHub. When we head back to GitHub, we can see that notification came up saying that print changes had a recent push. And when we look at the actual repository, you can see that it still has the original file and our changes haven't been merged in yet. And that's because it's within that new branch. So we can click on branches and see that print changes was pushed to the remote repository. Now to actually merge the changes from the branch into the main branch of the project, it's a good practice to use pull requests. And these allow other team members to approve the changes before it gets merged in. So let's create a new one now. So, we can go to the pull request tab and create a new pull request, and we can select the print changes branch, and it will show all the changes that we made here. And we can create a new pull request and we can leave a description of what we did, and it's usually good to write how to test make sure it's working. To test: make sure that the messages printed are printed from messages.py and new_file.py Thanks! And here we can add in reviewers, so we can link them to our project, and for now I'm not going to add anyone in. And you can add in labels and mark which project it's under and customize this pull request. And we create the pull request by clicking the button. And there it is. Now we can link this to other developers and we can add in reviewers. We can type in the email or their GitHub account and invite people to work on our projects. So, let's take a look at a large project with many team members working on multiple branches at the same time. So here's the Codecademy docs Git repository and
we can see it has lots of commits and 20 branches. And on the GitHub page, you can view the contents
of the repository, we can also view the issues that have come up, which people can create new branches
to address these changes, and we can also see all the pull requests. So if we click on the pull request tab and scroll through, we can view all the open pull requests and some information about them. So let's go ahead and check one out. We can see the description and some of them have checklists that follow the guidelines. And we can see that a review is required
before it can be merged into the main branch. So let's go back and we can also view all of the closed pull requests. Now these can be closed because it was denied or they were successfully merged in, so let's take a look at one of these. I have the description and the types of changes
described and we can see that some other developers are taking a look and commenting
on it, and they can make their own changes and add some modifications and we can follow the
trail all the way down to when it gets merged in. So there's a lot of great features in GitHub and there's also additional stuff like the
actions tab, which we can add in automation, such as actions that occur once someone pushes to the remote repository, different workflows, and there's lots of other features like
insights, which shows statistics about (inaudible). As you go through the lessons, make sure to think about how Git and GitHub can be used to track changes and improve
collaboration between team members. Thanks for watching the video and good luck!