What is it?
Git is a versioning tool that helps with managing projects and team collaboration. Git keeps a history of all changes made as well as when they were made. This helps when you need to go back and see when something changed or even revert back to a previous version.
GitHub is an online repository that uses Git.
Why use it?
One of the big concerns when working within a team is making sure that your work doesn't get overwritten by someone else. Git keeps everyone's work separate and merges the changes together. According to a recent survey, more than 70% of developers use Git which means if you ever work on a team, there's a good chance that you will work with Git.
Another nice feature is that you can separate tasks into different branches so that when one task is complete, it can be moved into production without having to wait for other active tasks to be completed.
How does it work?
The general workflow starts with your working tree. This represents all of the files in your working directory. Git tracks any changes that have been made and can display a list of those changes. These changes are saved through a series of steps to the root folder of your project on your local hard drive.
The last step in the process is to save the changes from your local hard drive to a repository in the cloud or on your network. The two main reasons for doing this are to collaborate with others or to make a backup copy of the original code.
When you need to retrieve the most up-to-date version of your project files, you pull them from the hosted repository back down to your local repository.
So the general process used to edit an existing project looks like this:
- Initialize a new repository OR
- Pull files from the hosted repository to your local computer.
- Modify the files and make your edits.
- Add the modified files to the Staging area.
- Commit the changes that have been staged.
- Merge the commitments to the main branch on your local repository. (1)
- Push your local repository to the the hosted repository.
(Note: Often when working on teams, a manager will handle merging. In that case, after the commit step, you would go straight to push, skipping the merge.)