Install and Explore Git
Learning Competencies
By the end of this challenge, you should be able to:
- Install Git
- Navigate repositories in GitHub
- Create a new repository
- Clone a repository
- Determine repository status
- Stage commits to a repository
Summary
Now that you understand version control, it's time to start using Git. You'll follow Udacity's Version Control with Git interactive course for this challenge.
Time Box
| Activity | Time |
|---|---|
| Read the How Git Works, Git Terminology and Git Commands sections | 15 minutes |
| Install and configure | 20 minutes |
| Try it out | 3 hours |
| Reflect | 20 minutes |
Stay on the path and follow the timebox suggestions.
How Git works
With Git, each project has a repository - a collection of all the versions of the project along with some special information - What order the changes occurred, a description of each change, who was responsible for each change etc.
Git doesn't automatically keep track of your versions - You have to explicitly tell it when you are finished so that Git will track them for you. The act of telling Git that the version is finished is called committing. Much like you would commit something to memory, you also commit changes to your repository. Because of this, versions are often referred to as commits. It doesn't make sense to treat unfinished work as a version in many cases. But in others, a commit might be a spelling correction or a fix to a broken link.
When you interact with your project, the complexity is hidden so that you won't even know it is there until you need to interact with it. Git has a set of tools to review your project history. For example, it can allow you to view or filter the complete list of commits or even switch what version your project is currently displaying. Do you want to look at what your project looked like this time last sprint, last month, and last year? Git will let you do all those things, often with just one command.
Git Terminology
Shared via Readwrite.com
Command Line - The computer program we use to input Git commands. On a Mac, it’s called Terminal. On a PC, it’s a non-native program that you download when you download Git for the first time. In both cases, you type text-based commands, known as prompts, into the screen, instead of using a mouse.
Repository - A directory or storage space where your projects can live. Sometimes GitHub users shorten this to “repo.” It can be local to a folder on your computer or storage space on GitHub or another online host. You can keep code files, text files, image files, you name it, inside a repository.
Version Control - Basically, the purpose Git was designed to serve. When you have a Microsoft Word file, you either overwrite every saved file with a new save or save multiple versions. With Git, you don’t have to. It keeps “snapshots” of every point in time in the project’s history, so you can never lose or overwrite it.
Commit - This is the command that gives Git its power. When you commit, you are taking a “snapshot” of your repository at that point in time, giving you a checkpoint to which you can reevaluate or restore your project to any previous state.
Branch - How do multiple people work on a project simultaneously without Git getting them confused? Usually, they “branch off” of the main project with their own versions full of changes they themselves have made. After they’re done, it’s time to “merge” that branch back with the “main,” the project's main directory.
Git Commands
Shared via Readwrite.com
Since Git was designed with a big project like Linux in mind, there are many Git commands. However, to use the basics of Git, you’ll only need to know a few phrases. They all begin the same way, with the word git.
A few essential commands to get familiar with
git clone - Copy an existing repository from a target location (such as GitHub) and create a matching version on your computer.
git status - Check the status of your repository. See which files are inside it, which changes still need to be committed, and which branch of the repository you’re currently working on.
git add - This does not add new files to your repository. Instead, it brings new files to Git’s attention. After you add files, they’re included in Git’s “snapshots” of the repository.
git commit - Git’s most important command. After you make any change, you input this to take a “snapshot” of the repository. Usually, it goes git commit -m “Message here”. The -m indicates that the following section of the command should be read as a message.
git push - If you’re working on your local computer and want your commits to be visible online on GitHub, you “push” the changes up to GitHub with this command.
git help - Forgot a command? Type this into the command line to bring up the 21 most common Git commands. You can also be more specific and type git help init or another term to figure out how to use and configure a specific Git command.
git config - Short for “configure” is most useful when setting up Git for the first time.
git init - Initializes a new Git repository, i.e. turns the current folder into a Git folder. It's just a regular folder until you run this command inside a repository or directory. Only after you input git init does it accept further Git commands.
git pull - If you’re working on your local computer and want the most up-to-date version of your repository to work with, you “pull” the changes down from GitHub with this command. It is useful when working on the same repository as someone else or on different computers.
git branch - Working with multiple collaborators and want to make changes on your own? This command will let you build a new branch (or timeline of commits, changes and file additions) that is entirely your own. Your title goes after the command. If you wanted a new branch called “cats”, you’d type git branch cats.
git checkout - This allows you to “check out” or take a look at a different branch in your project. You can use this command as git checkout main to look at the main branch or git checkout cats to look at the cats' branch.
git merge - When you’re done working on a branch, you can merge your changes back to the main branch, which is visible to all collaborators. git merge cats would take all the changes you made to the “cats” branch and add them to the main.
Version Control with Git - Course
Complete Lessons 1 - 4 of the Version Control with Git Course (stop at Lesson 5 - 'Tagging, Branching, Merging'). Also, please skip the computer set-up instructions in Lesson 1. Git will have been configured when you did your computer set-up. Though your terminal might look slightly different than what you see in the tutorial, the exercise should all work the same.
Extra Resources (optional)
Reflect
On the same text document as your last reflection, answer these questions:
In your reflection, answer the questions:
- What is a Git workflow?
- What did you notice about your learning? What did you do when you were confused or blocked?
- Is there anything you'd do differently if you were to repeat the learning exploration?