Lesson #3 - What is Git/GitHub?
Remember how we made you read a whole page explaining the internet in 3 levels of complexity? Get ready for your next 1 in 3 (or should I say Git ready).
Part 1: Explaining it to a Child
Git and GitHub are tools that help developers collaborate and safely store their code.
Developers need a place to safely store their code. Imagine you kept all your projects on your computer and your computer was stolen! You could lose months of work. Just like Dropbox is used to back up documents, GitHub is an online space to store code. GitHub also allows you to share code with other people and work together on projects.
Git is a software application that runs on your machine and allows you to add things to GitHub and download things from GitHub.
Part 2: Explaining it to an Adult
What is Git?
Git is a version control software that runs on your computer.
Git serves two primary purposes:
-
It tracks changes to any files in your project. If you have a working application and you accidentally break it, you can roll it back to a previous point. Unlike Microsoft Word or similar programs, not only can you go back to the previous saved point, but you can go back to any point in time that you saved.
-
It allows you to add (push) and download (pull) code from your online code repository on GitHub. This functionality is similar to the Dropbox client that syncs your local files with Dropbox.
Real World Example:
Imagine you're playing a video game and there's a key you can press to save at any time you want. Perhaps you saved twice in level 1, once in level 2, and once in level 3. The game is going well, but suddenly it takes a turn for the worst. Your health is waning, your energy is low, and you're down to your last life. Not to worry, you can go back to any of your save points!
The save point from level 3 seems like the obvious choice because you were the furthest along in the game at that point. You pop back to the level 3 saved version and bam! Your game is just as you it in level 3. Health is great, energy is high, and you have lives to spare. Life is good...
But before too long you end up back in the same predicament and it seems like maybe the bad decisions that lead actually occurred long before level 3. You pop back to your second saved version on level 1 and whiz through the game with ease!
This video game example is a scenario that happens in software development frequently. Suppose you are building an event management software for a local event planner. They ask you to add a calendar widget so clients can see available dates. You're working on this over a few days, it's going great, but you code yourself into a corner and break the entire application trying to figure it out. Not to worry! If you used git and saved (pushed) frequently enough, you can roll back to exactly the point where you took a wrong turn.
What is Github?
GitHub is a web-based storage solution for developers. It's like the developer's Dropbox or Google Drive. You can store code for safe keeping and share it with others. But it's so much more than that! It's also a version control system.
Suppose you are managing a team of 5 developers and they are all working on a project. Quality is dropping and more bugs are slipping into production. You find the offending files.
Want to know who wrote them?
GitHub can tell you that.
Want to know who reviewed them and said they were okay?
GitHub has that info too.
How about rolling back to a previous version when things were more stable?
Easy Peesy.
GitHub also helps developers collaborate. Let's take a look at the example below.
Real World Example:
Janet and Tasha are working together on a login feature. The design files call for two shades of green and a shade of yellow to be used on the site. Janet is working on the login box and adds a green background. Tasha is working on the same feature and adds a purple background. They aren't using GitHub and Janet uploads her files first, followed closely by Tasha. What color is the background? It's purple. This is definitely not right, but whoever pushes last wins in the wild world of the GitHub-less.
Let's take a look at the same scenario with GitHub:
Janet pushes her code and it's merged into the production code. Tasha pushes her code, but GitHub blocks it from being merged. There's a conflict! Someone on the team has to review the code, check the conflict, and choose which code is correct. Their teammate Alysha reviews the code, notices that the purple doesn't match the design files and tells GitHub to use the green background before merging the rest of Tasha's code.
Tada! Cloud storage, version control, and source code management all in one!
Part 3: Explaining it to a Future Developer
What is Git?
Git is the most widely used version control system. Version control is software that helps a team manage changes to its source code. Git was created originally in 2005 to manage the Linux kernel. Nowadays it is used across the world for an unfathomably huge number of software projects.
Git tracks your changes to the source code via commits, and syncs with a remote source, like GitHub or Bitbucket, via push (to send your commits to the remote) or pull (to retrieve commits from the remote) commands.
What is Github?
GitHub is an online space to work collaboratively on projects and keep your code safe.
Most software requires teams of developers to work simultaneously in a safe way. GitHub is a tool that allows us to do that. It is a powerful tool on which all developers rely heavily.
Virtually every software company stores its code in GitHub or a similar service.
How do I use Git and GitHub?
This handy video can walk you through the below steps:
- Create a new repository named
prework-repository
. When creating the repository, make sure that theInitialize this repository with a README
box is checked! By default it is unchecked. - After the repository has been created, click on the green
Clone or download
button. Be sure thatUse HTTPS
is toggled (We will not be using SSH). Then copy the link provided!
- In the terminal or GitBash,
cd
into the directory where you want your version of the repository to live. - Clone the repo using
git clone <repo name>
. cd
into your new local version of the repository.- Create a file within your new local version of the repository.
- Stage the changes using
git add -A
. - Commit the changes using
git commit -m "some message"
. - Push the changes using
git push origin master
. - Pat yourself on the back, you've just created a respository, cloned it to your local machine, made changes, and pushed it up to the repo!