Project: Practicing Git Basics (v1)

Introduction

This short project will demonstrate how to use Git to manage and track your project folders.

  1. You will set up a remote repository on GitHub and then copy it onto your local machine.
  2. Once this repo is set up locally, you will be able to use Git like a save button for your files and folders.
  3. When you have finalized your saves, you can then push your local repo up onto GitHub to share with everyone!

Learning Objectives

By the end of this lesson, you should be able to do the following:

  • Create a Git repository on GitHub and copy it onto your local machine.
  • Describe the difference between staging and committing changes.
  • Describe the difference between committing your changes and pushing them onto GitHub.
  • Explain how to check the status of your current repository from the command line.
  • Explain how to look at the history of your previous commits from the command line.

Assignment

In this project, we’ll walk through the basic Git workflow that you will use in all your projects.

Create the Repository

  1. You should have already created a GitHub account in the Setting up Git lesson. If you haven’t done that yet, you can sign up here.

  2. Create a new repository by clicking the button shown in the screenshot below.

New Repository

  1. Give your repository the name "git_test" in the repository name input field, and create the repository by clicking the green "Create repository" button at the bottom of the page.

  2. This will redirect you to your new repository on GitHub. To copy this repository onto your local machine, select the SSH option and copy the line next to it.

GitHub-SSH

  1. In the command line on your local machine, navigate to where you want to store this project, and then clone your repository on GitHub onto your computer with git clone followed by the URL you copied in the last step. The full command should look similar to:
git clone git@github.com:USER-NAME/REPOSITORY-NAME.git

git clone

  1. That’s it! You have successfully connected the repository you created on GitHub to your local machine. To test this, you can cd into the new git_test folder that was downloaded and then enter git remote -v in your command line. This will display the URL of the repository you created in GitHub, which is the remote for your local copy.
cd git_test
git remote -v

You may have also noticed the word origin at the start of the git remote -v output, which is the name of your remote connection. The name "origin" is both the default and the convention for the remote repository, but it could have just as easily been named "party-parrot" or "dancing-banana". (Don’t worry about the details of origin for now; it will come up again near the end of this tutorial.)

git origin

Use the Git Workflow

  1. Create a new file in the git_test folder called "README.md" with the command touch README.md.

touch README

  1. Type git status in your terminal. In the output, notice that your README.md file is shown in red, which means that this file is not staged.

git status

  1. Type git add README.md. This command adds your README.md file to the staging area in Git. Now, type git status again. In the output, notice that your file is now shown in green, which means that this file is now in the staging area.

git add README

  1. Type git commit -m "Add README.md" and then type git status once more. The output should now say, "nothing to commit", indicating that your changes have been committed.

git commit README

  1. Type git log and look at the output. You should see an entry for your "Add README.md" commit. You will also see details on the author who made the commit and the date and time for when the commit was made.

Add Another File

  1. Create a new file in the git_test folder called hello_world.txt. In the terminal, type git status, and notice hello_world.txt is not staged.

git test

  1. Open README.md in your text editor of choice and add the text "This is (YourUsername)’s first git project!" and then save the file.

first README

  1. Back in your terminal, type git status, and notice that README.md is now shown as modified, and not staged or committed. This is because you made a change to it, and it is already a tracked file.

git status modified

  1. Add README.md to the staging area with git add README.md.

  2. Can you guess what git status will output now? README.md will be displayed in green text, while hello_world.txt will still be in red. This means that only README.md has been added to the staging area.

  1. Now, add hello_world.txt to the staging area with a slightly different command: git add ., where the full stop means to add all files that are not staged. Then, type git status once more, and everything should now be in the staging area.

  1. Finally, let’s commit all of the files that are in the staging area and add a descriptive commit message git commit -m "Add hello_world.txt and edit README.md". Then, type git status once again, which will output "nothing to commit".

  1. Take one last look at your commit history by typing git log. You should now see two entries.

Push Your Work to GitHub

Finally, let’s upload your work to the GitHub repository you created at the start of this tutorial.

  1. Type git push origin master.

  1. Type git status one final time. It should output "nothing to commit, working tree clean".

  1. When you reload the repository on GitHub, you should see the README.md and hello_world.txt files that you just pushed there from your local machine.

Conclusion

The main take away from the past few lessons is how to use Git and GitHub for your projects. You now have this very powerful skill that will help you immensely when we get into the coding projects. You will be able to share your work with others for code reviews and to get help with your code if you’re stuck.

In later Git lessons, we will cover some of the more advanced Git features, such as branches, which will further expand your abilities and make you more productive.

For now, concentrate on using the basics of Git that you’ve learned here with all of your projects from now on. You will soon know each of the basic Git commands from memory!

Additional Resources

This section contains helpful links and supplemental content.

LOOKING FOR HELP?

When looking for help, try doing so in the following order:

  • Did you try everything you could?
  • Did you read the documentation?
  • Did you Google for it?
  • Did you post your question on Slack/Forum?
  • Did you ask your fellow students for help?
  • Did you ask your Mentors for help?
  • Did you leave a comment on the comments section of this page?
  • Did you ask your Instructor for help?
    • Did you arrange and appointment with your instructor using Calendly? Visit this URL and set up an appointment: https://calendly.com/kostasx
    • Is it urgent? Did you try reaching him on Slack

UPDATED: 25.10.2020

Git Basics – Part II (v1)

Introduction

In this lesson, we’ll cover common Git commands used to manage your projects and to upload your work onto GitHub. We refer to these commands as the basic Git workflow. When you’re using Git, these are the commands that you’ll use 70-80% of the time, so if you can get these down, you’ll be more than halfway done mastering Git!

Learning Objectives

By the end of this lesson, you should be able to do the following:

  • Describe how to copy an existing repository from Github onto your local machine.
  • Explain the two-stage system that Git uses to save files.
  • Describe how to upload your work to GitHub using Git.
  • Describe how to check the status of your files and how to view your commit history.

Assignment

  1. Watch the next video by Corey Schafer for a great overview of some basic Git commands.

  1. Read 5 Git Commands You Should Know, with Code Examples and spend some time practicing on the commands described in the post.

  2. Follow this excellent guide on how to Learn Git and Version Control in an Hour by Amarachi Emmanuela Azubuike . Student Approved Resource

Cheatsheet

This is a reference list of the most commonly used Git commands. (You might consider bookmarking this handy page.) Try to familiarize yourself with the commands so that you can eventually remember them all:

  • Commands related to a remote repository:
    • git clone git@github.com:USER-NAME/REPOSITORY-NAME.git or git clone https://github.com/user-name/repository-name.git
    • git push origin master
  • Commands related to workflow:
    • git add .
    • git commit -m "A message describing what you have done to make this snapshot different"
  • Commands related to checking status or log history
    • git status
    • git log

The basic Git syntax is program | action | destination.

For example,

  • git add . is read as git | add | ., where the period represents everything in the current directory;
  • git commit -m "message" is read as git | commit -m | "message"; and
  • git status is read as git | status | (no destination).

Live Session

Watch the following live session that was recorded on 23/09/2020 to understand more about the basic concepts of Git and walk yourselves through some basic examples.

Part I | Duration: 1h 33m

Part II | Duration: 1h 30m

Part III | Duration: 1h 24m

Conclusion

You may not feel completely comfortable with Git at this point, which is normal. It’s a skill that you will get more comfortable with as you use it. Therefore, we have a project coming right after this lesson where we’ll walk you through the entire Git workflow, which is the exact same process you would use in a real project.

The main thing to take away from this lesson is the basic workflow. The commands you’ve learned here are the ones you will be using the most often with Git.

Don’t worry if you don’t know all the commands yet or if they aren’t quite sticking in your memory yet. They will soon be seared into your brain as you use them over and over in future projects.

Additional Resources

Duration: 12 minutes

Knowledge Check

This section contains questions for you to check your understanding of this lesson. If you’re having trouble answering the questions below on your own, clicking the small arrow to the left of the question will reveal the answers.

What is the Git command used to get a full copy of an existing Git repository from Github?
    • Use git clone git@github.com:<your-github-username>/<your-respository-name> to clone a GitHub repository onto your local machine.
What is the Git command used to check the status of your files?
    • Use git status to see any changes made since your last commit.
What is the Git command used to track files with Git?
    • Use git add to track files.
What is the Git command used to commit files?
    • Use git commit to commit tracked files.
What is the Git command used to view your commit history?
    • Use git log to view your commit history.
What is the Git command used to upload projects onto GitHub?
    • Use git push to send your commit to GitHub.
Explain the two-stage system that Git uses to save files.
    • A save in Git is divided into two terminal commands: add and commit. The combination of these two commands gives you control of exactly what you want to be remembered in your snapshot.
    • Staging: Think of add as adjusting the number of people or elements to be included in a photo. With Git, you can select the changes you want to save with git add. Imagine a project that contains multiple files where changes have been made to several files. You want to save some of the changes you have made and leave some other changes to continue working on them.
    • Committing: Think of commit as actually taking a photo, resulting in a snapshot. For example, to commit a file named README.md, type git commit -m "Add README.md". The -m flag stands for “message” and must always be followed by a commit message inside quotation marks. In this example, the commit message was "Add README.md".
Explain what origin is in git push origin master.
    • In Git, origin is a placeholder name for the URL of the remote repository. Git sets up the origin by default when it clones a remote repository. You can use origin to access the remote repository without having to enter a full URL every time. This also means that you can have multiple remotes for a repository by giving each a unique name.
Explain what master is in git push origin master.
    • In Git, master is the branch of the remote repository you want to push your changes to. We will get more into branches in a later lesson, but the main thing to remember is that master is the official branch in your projects where production-ready code lives.

Material based on Erik Trautman | The Odin Project
LOOKING FOR HELP?

When looking for help, try doing so in the following order:

  • Did you try everything you could?
  • Did you read the documentation?
  • Did you Google for it?
  • Did you post your question on Slack/Forum?
  • Did you ask your fellow students for help?
  • Did you ask your Mentors for help?
  • Did you leave a comment on the comments section of this page?
  • Did you ask your Instructor for help?
    • Did you arrange and appointment with your instructor using Calendly? Visit this URL and set up an appointment: https://calendly.com/kostasx
    • Is it urgent? Did you try reaching him on Slack

UPDATED: 10.03.2021

CONTRIBUTORS:

Git Basics – Part I (v1)

Reading Time

Until you understand the concepts upon which Git is built, you’ll feel like a stranger in a foreign land., Tom Preston-Werner, author of The Git Parable

"The following parable will take you on a journey through the creation of a Git-like system from the ground up. Understanding the concepts presented here will be the most valuable thing you can do to prepare yourself to harness the full power of Git.

The concepts themselves are quite simple, but allow for an amazing wealth of functionality to spring into existence. Read this parable all the way through and you should have very little trouble mastering the various Git commands and wielding the awesome power that Git makes available to you."

Download and read the The Git Parable

Reading time: 30 to 60 minutes.

Study & Practice Time

Take a 5 to 10 minute break before diving into the next video, as you will not only be learning about the basics of Git and version control, but you will also be practicing these concepts on your own Git repository.

Although the video duration is close to 15 minutes, this session will probably take more than 1 hour (or even more), since you will be practicing along with Colt Steele.

We suggest that you run the commands through the integrated terminal of VSCode. (Tip: Press Ctrl+J to open/close the terminal while in VSCode)

Duration: 16 minutes

Additional Resources

This section contains helpful links to other content. It isn’t required, but you should consider it supplemental if you need to dive deeper into Git and Version Control.

Knowledge Check

This section contains questions for you to check your understanding of this lesson. If you’re having trouble answering the questions below on your own, clicking the small arrow to the left of the question will reveal the answers.

What kind of program is Git?
    • Git is a version control program.
What are the differences between Git and a text editor in terms of what they save and their record keeping?
    • A text editor can only make and save changes to a file.
    • Git tracks changes to the files and their contents over time.
Does Git work at a local or remote level?
    • Git works on a local level. Any changes you make are saved locally with Git.
Does GitHub work at a local or remote level?
    • GitHub works on a remote level. You must push your local changes (using Git) to Github.
Why is Git useful for an individual developer?
    • Git is useful for creating snapshots of your work. If you realize halfway through that you’ve messed up, it’s much easier to reset.
Why are Git and GitHub useful for a team of developers?
    • Git and GitHub are useful for teams because they can merge code together. A developer can work on one part of the code while a second developer works on another part. They can then use Git and GitHub to easily combine their changes.
LOOKING FOR HELP?

When looking for help, try doing so in the following order:

  • Did you try everything you could?
  • Did you read the documentation?
  • Did you Google for it?
  • Did you post your question on Slack/Forum?
  • Did you ask your fellow students for help?
  • Did you ask your Mentors for help?
  • Did you leave a comment on the comments section of this page?
  • Did you ask your Instructor for help?
    • Did you arrange and appointment with your instructor using Calendly? Visit this URL and set up an appointment: https://calendly.com/kostasx
    • Is it urgent? Did you try reaching him on Slack

UPDATED: 25.10.2020

Introduction to Git (v1)

Prerequisites

Before moving on to this section, you must feel comfortable working with the terminal, be able to execute basic commands and manipulate files and folders using command line utilities like cd, ls, touch, rm, etc.

Learning Objectives

By the end of this lesson, you should be able to do the following:

  • Explain what Git and GitHub are and the differences between the two.
  • Describe the differences between Git and a text editor in terms of what they save and their record keeping.
  • Describe why Git is useful for an individual developer and a team of developers.
  • Explain what Version Control is

Introduction

Watch the next videos to learn about the history of Git and GitHub.

Duration: 5 minutes

What’s the Difference between Git and GitHub?

Duration: 2 minutes

Duration: 4 minutes

A Detailed Overview

Git is like a really epic save button for your files and directories. Officially, Git is a version control system.

A save in a text editor records all of the words in a document as a single file. You are only ever given one record of the file, such as essay.doc, unless you make duplicate copies (which is difficult to remember to do and keep track of):

essay-draft1.doc, essay-draft2.doc, essay-final.doc

However, a save in Git records differences in the files and folders AND keeps a historical record of each save. This feature is a game changer. As an individual developer, Git enables you to review how your project grows and to easily look at or restore file states from the past. Once connected to a network, Git allows you to push your project to GitHub for sharing and collaborating with other developers.

While Git works on your local machine, GitHub is a remote storage facility on the web for all your coding projects. This means that by learning Git, you will get to showcase your portfolio on GitHub! This is really important because almost all software development companies consider using Git to be an essential skill for modern web developers. Having a GitHub portfolio will provide proof to future potential employers as to what you are capable of.

In this lesson, we will briefly explore the history of Git, what it is, and what it’s useful for.

In the next lesson, we will go over the basic workflow for using Git, which should enhance your understanding and demonstrate why Git is so useful.

Finally, you will set up a project with Git that will serve as a template for your future projects.

For now, let’s learn what Git is and why it’s so powerful!

Terminology

Before moving on, we should familiarize ourselves with the basic terms of Version Control and Git.

Download this Cheat Sheet (PDF), take a first look at each term and make sure to keep this file open while you go through the Git lessons, as you will need to come back to this terms sheet quite often.


Material based on Erik Trautman | The Odin Project
LOOKING FOR HELP?

When looking for help, try doing so in the following order:

  • Did you try everything you could?
  • Did you read the documentation?
  • Did you Google for it?
  • Did you post your question on Slack/Forum?
  • Did you ask your fellow students for help?
  • Did you ask your Mentors for help?
  • Did you leave a comment on the comments section of this page?
  • Did you ask your Instructor for help?
    • Did you arrange and appointment with your instructor using Calendly? Visit this URL and set up an appointment: https://calendly.com/kostasx
    • Is it urgent? Did you try reaching him on Slack

UPDATED: 02.04.2021

Contributors:

Git Basics – Part I

LOOKING FOR HELP?

When looking for help, try doing so in the following order:

  • Did you try everything you could?
  • Did you read the documentation?
  • Did you Google for it?
  • Did you post your question on Slack/Forum?
  • Did you ask your fellow students for help?
  • Did you ask your Mentors for help?
  • Did you leave a comment on the comments section of this page?
  • Did you ask your Instructor for help?
    • Did you arrange and appointment with your instructor using Calendly? Visit this URL and set up an appointment: https://calendly.com/kostasx
    • Is it urgent? Did you try reaching him on Slack
LOOKING FOR HELP?

When looking for help, try doing so in the following order:

  • Did you try everything you could?
  • Did you read the documentation?
  • Did you Google for it?
  • Did you post your question on Slack/Forum?
  • Did you ask your fellow students for help?
  • Did you ask your Mentors for help?
  • Did you leave a comment on the comments section of this page?
  • Did you ask your Instructor for help?
    • Did you arrange and appointment with your instructor using Calendly? Visit this URL and set up an appointment: https://calendly.com/kostasx
    • Is it urgent? Did you try reaching him on Slack

Project: Practicing Git Basics

NOTICE: All new Git repositories on GitHub will be named "main" instead of "master" starting October 1, 2020 as part of the company’s effort to remove unnecessary references to slavery and replace them with more inclusive terms.

Introduction

Now we will create a project that will show us how to use Git to manage and track our project folders.

More specifically:

  1. We will set up a remote repository on GitHub and then copy it onto our local machine.
  2. Once our repo is set up locally, we will use Git to save our files and folders.
  3. When we have finalized our saves, then we will push our local repo up onto GitHub to share with everyone!

Learning Objectives

  • Create a Git repository on GitHub and then copy it onto our local machine
  • Explain the difference between staging and committing changes
  • Explain the difference between committing your changes and pushing them onto GitHub
  • Check the status of our current repository using the command line
  • Look at the history of our previous commits using the command line

Start our Project

In this project, we’ll walk through the basic Git workflow that you will use in all your projects.

STEP 1: Create the Repository

In this step we will create a repository and we will connect it to Github.

  1. You should have already created a GitHub account in the Setting up Git lesson. If you haven’t done that yet, you can sign up here.

  2. Create a new repository by clicking the button shown in the screenshot below.

New Repository

  1. Give your repository the name "git_test" in the repository name input field, and create the repository by clicking the green "Create repository" button at the bottom of the page.

  2. This will redirect you to your new repository on GitHub. In order to copy this repository onto your local machine, select the SSH option and copy the line next to it.

GitHub-SSH

  1. On your local machine in the command line, navigate to where you want to store this project. Then clone your repository on GitHub onto your computer with git clone followed by the URL you copied in the last step. The full command should look similar to:
git clone git@github.com:USER-NAME/REPOSITORY-NAME.git

git clone

  1. That’s it! You have successfully connected the repository you created on GitHub to your local machine.

  2. To test this, you can cd into the new git_test folder that was downloaded and then enter git remote -v in your command line. This will display the URL of the repository you created in GitHub, which is the remote for your local copy.

cd git_test
git remote -v

git origin

Once you have typed the commands above you may have also noticed the word origin at the start of the git remote -v output. This is the name of your remote connection and thus the name "origin" is both the default and the convention for the remote repository. However this name could have just been whatever you wanted. Don’t worry about the details of origin for now we will see more of it at the end of this tutorial.

STEP 2: Use the Git Workflow

In this step we will create a file using the git workflow.

  1. Create a new file in the git_test folder called "README.md" with the command touch README.md.

touch README

  1. Type git status in your terminal. In the output, notice that your README.md file is shown in red, which means that this file is not staged.

git status

  1. Type git add README.md. This command adds your README.md file to the staging area in Git. Now, type git status again. In the output, notice that your file is now shown in green, which means that this file is now in the staging area.

git add README

  1. Type git commit -m "Add README.md" and then type git status once more. The output should now say, "nothing to commit", indicating that your changes have been committed.

git commit README

  1. Type git log and look at the output. You should see an entry for your "Add README.md" commit. You will also see details on the author who made the commit and the date and time for when the commit was made.

STEP 3: Add Another File

In this step we will add another file to our repository using the same logic.

  1. Create a new file in the git_test folder called hello_world.txt. In the terminal, type git status, and notice hello_world.txt is not staged.

git test

  1. Open README.md in your text editor of choice and add the text "This is (YourUsername)’s first git project!" and then save the file.

first README

  1. Back in your terminal, type git status, and notice that README.md is now shown as modified, and not staged or committed. This is because you made a change to it, and it is already a tracked file.

git status modified

  1. Add README.md to the staging area with git add README.md.

  2. Can you guess what git status will output now? README.md will be displayed in green text, while hello_world.txt will still be in red. This means that only README.md has been added to the staging area.

  1. Now, add hello_world.txt to the staging area with a slightly different command: git add ., where the full stop means to add all files that are not staged. Then, type git status once more, and everything should now be in the staging area.

  1. Finally, let’s commit all of the files that are in the staging area and add a descriptive commit message git commit -m "Add hello_world.txt and edit README.md". Then, type git status once again, which will output "nothing to commit".

  1. Take one last look at your commit history by typing git log. You should now see two entries.

STEP 4: Push Your Work to GitHub

In this step we will upload our work to the GitHub repository we created at the start of this tutorial.

  1. Type git push origin main.

  1. Type git status one final time. It should output "nothing to commit, working tree clean".

  1. When you reload the repository on GitHub, you should see the README.md and hello_world.txt files that you just pushed there from your local machine.

Conclusion

From the past few lessons and from this project you should now have a very clean idea of how and why to use Git and GitHub for your projects. You should have realized what powerful tools are and how much they will help you to your goal of becoming a web developer.

Later on we will learn more about Git and specifically git branches, which will further expand your abilities and make you more productive.

From now on you should use all the basics from Git to your projects.

Additional Resources

In this section you can find a lot of helpful links to other content. This is a supplemental material for you if you want to dive deeper into some concepts.


The archived old version of this post can be found here

UPDATED: 03.06.2021

LOOKING FOR HELP?

When looking for help, try doing so in the following order:

  • Did you try everything you could?
  • Did you read the documentation?
  • Did you Google for it?
  • Did you post your question on Slack/Forum?
  • Did you ask your fellow students for help?
  • Did you ask your Mentors for help?
  • Did you leave a comment on the comments section of this page?
  • Did you ask your Instructor for help?
    • Did you arrange and appointment with your instructor using Calendly? Visit this URL and set up an appointment: https://calendly.com/kostasx
    • Is it urgent? Did you try reaching him on Slack

Git Basics – Part II

NOTICE: All new Git repositories on GitHub will be named "main" instead of "master" starting October 1, 2020 as part of the company’s effort to remove unnecessary references to slavery and replace them with more inclusive terms.

Introduction

In this lesson, we will see some basic commands that are very useful not only to manage your projects but also to upload your work onto GitHub. These commands are used very often and that’s why we refer to them as the basic Git workflow. So once you have learned and mastered these commands you would be more than half away done mastering the entire Git!

Learning Objectives

  • Understand how to copy an existing repository from Github onto your local machine.
  • Describe the two-stage system that Git uses to save files.
  • Understand and explain how to upload your work to GitHub using Git.
  • Understand and explain how to check the status of your files and how to view your commit history.

Study

  1. Watch the next video by Corey Schafer for a great overview of some basic Git commands.

  1. Read 5 Git Commands You Should Know, with Code Examples and spend some time practicing on the commands described in the post.

  2. Follow this excellent guide on how to Learn Git and Version Control in an Hour by Amarachi Emmanuela Azubuike . Student Approved Resource

Git Commands Cheatsheet

Now we will see a list of the most commonly used Git commands. We advise you to bookmark this page and also try to familiarize yourself with the commands. Eventually you will remember them all.

  • Commands related to a remote repository:
    • git clone git@github.com:USER-NAME/REPOSITORY-NAME.git or git clone https://github.com/user-name/repository-name.git
    • git push origin main
  • Commands related to workflow:
    • git add .
    • git commit -m "A message describing what you have done to make this snapshot different"
  • Commands related to checking status or log history
    • git status
    • git log

The basic Git syntax is program | action | destination.

For example,

  • git add . is read as git | add | ., where the period represents everything in the current directory;
  • git commit -m "message" is read as git | commit -m | "message"; and
  • git status is read as git | status | (no destination).

Live Session

Watch the following live session that was recorded on 23/09/2020 to understand more about the basic concepts of Git and walk yourselves through some basic examples.

Part I | Duration: 1h 33m

Part II | Duration: 1h 30m

Part III | Duration: 1h 24m

Conclusion

Although you might have watched and read all the assignments listed above you might still not feeling very comfortable using Git. Don’t worry if that’s the case. Git is something you learn and understand better as you use it.

For this reason in our next lesson we will see a project that will walk you through the entire Git workflow. This process is the same process you would use in a real project as a web developer.

Don’t worry if some of the commands are not sticking in your memory yet. The important thing that you need to get from this lesson is the basic workflow. The rest of the commands will be learned as you use them in future projects.

Additional Resources

In this section you can find a lot of helpful links to other content. This is a supplemental material for you if you want to dive deeper into some concepts.

Duration: 12 minutes

Check Your Knowledge

Now it is time to check your knowledge and your understanding of this lesson. If you stuck in a question just click the small arrow to the left and an answer will be revealed.

Which Git command should we use to get a full copy of an existing Git repository from Github?
    • We should use the git clone git@github.com:<your-github-username>/<your-repository-name> command to clone a GitHub repository onto our local machine.
Which Git command should we use to check the status of our files?
    • We should use the git status command to see any changes made since our last commit.
Which Git command should we use to track files?
    • We should use the git add command to track files.
Which Git command should we use to commit files?
    • We should use thegit commit command to commit tracked files.
Which Git command should we use to view our commit history?
    • We should use the git log command to view our commit history.
Which Git command should we use to upload projects onto GitHub?
    • We should use the git push command to send our commit to GitHub.
Describe the two-stage system that Git uses to save files.
    • A save in Git is divided into two terminal commands: add and commit. The combination of these two commands gives you control of exactly what you want to be remembered in your snapshot.
    • Staging: With Git, you can select the changes you want to save with git add. For example let’s say you have a project that contains multiple files and changes have been made to several files. If you want to save some of the changes you have made and leave some other changes to continue working on them then you will use git add.
    • Committing: Thecommit is actually resulting in a snapshot. For example, let’s say that you want to commit a file named README.md. Then you need to type git commit -m "Add README.md". The -m flag stands for “message” and must always be followed by a commit message inside quotation marks. In this example, the commit message was "Add README.md".
What is the word origin means in the git push origin main command?
    • The word origin in Git is a placeholder name for the URL of the remote repository. Once you clone a repository Git sets up the origin by default. Therefore, we can use origin to access the remote repository without having to enter a full URL every time. We can also have multiple remotes for a repository by giving each a unique name.
What is the word main means in the git push origin main command?
    • The word main in Git is the branch of the remote repository we want to push our changes to. Although you may not be familiar with branches yet, the main thing to remember is that main is the official branch in your projects where production-ready code lives.

The archived old version of this post can be found here

UPDATED: 03.06.2021

CONTRIBUTORS:

LOOKING FOR HELP?

When looking for help, try doing so in the following order:

  • Did you try everything you could?
  • Did you read the documentation?
  • Did you Google for it?
  • Did you post your question on Slack/Forum?
  • Did you ask your fellow students for help?
  • Did you ask your Mentors for help?
  • Did you leave a comment on the comments section of this page?
  • Did you ask your Instructor for help?
    • Did you arrange and appointment with your instructor using Calendly? Visit this URL and set up an appointment: https://calendly.com/kostasx
    • Is it urgent? Did you try reaching him on Slack

Introduction to Git

NOTICE: All new Git repositories on GitHub will be named "main" instead of "master" starting October 1, 2020 as part of the company’s effort to remove unnecessary references to slavery and replace them with more inclusive terms.

Prerequisites

Before moving on to this section, you must feel comfortable working with the terminal, be able to execute basic commands and manipulate files and folders using command line utilities like cd, ls, touch, rm, etc.

Learning Objectives

  • Understand what Git and GitHub are and explain the differences between the two.
  • Understand the differences between Git and a text editor in terms of what they save and their record keeping.
  • Understand why Git is useful for an individual developer and a team of developers.
  • Explain what Version Control is

Introduction

Watch the next videos to learn about the history of Git and GitHub.

Duration: 5 minutes

What’s the Difference between Git and GitHub?

Duration: 2 minutes

Duration: 4 minutes

A Detailed Overview

Officially, Git is a version control system. Git is like a really epic save button for your files and directories.

When you save a file in a text editor such a .doc document you only save a record of all the words in a document as a single file. So you have access to that record only unless you make many duplicates of the same file. However this is difficult to remember and it is inefficient.

On the other hand when you save in Git, Git records differences in the files and folders. Most importantly keeps a historical record of each save. This is really handy since it enables you to review how the code works and easily go back to previous saves. Therefore you have the ability to look or restore file states from the past. In addition, Git allows you to push your project to GitHub for sharing and collaborating with other developers.

So Git works on our local machine, whereas GitHub is a remote storage facility on the web. It is essential to learn Git because in Git and Github are used from many developers to showcase their work. Having a portfolio of projects on Github is really important because it is a proof to future potential employers as to what you can do.

Terminology

Before moving on, we should familiarize ourselves with the basic terms of Version Control and Git.

Download this Cheat Sheet (PDF), take a first look at each term and make sure to keep this file open while you go through the Git lessons, as you will need to come back to this terms sheet quite often.


The archived old version of this post can be found here

UPDATED: 02.04.2021

Contributors:

LOOKING FOR HELP?

When looking for help, try doing so in the following order:

  • Did you try everything you could?
  • Did you read the documentation?
  • Did you Google for it?
  • Did you post your question on Slack/Forum?
  • Did you ask your fellow students for help?
  • Did you ask your Mentors for help?
  • Did you leave a comment on the comments section of this page?
  • Did you ask your Instructor for help?
    • Did you arrange and appointment with your instructor using Calendly? Visit this URL and set up an appointment: https://calendly.com/kostasx
    • Is it urgent? Did you try reaching him on Slack