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
Watch this video 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
Let’s start with one of our recorded sessions about Git & GitHub
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.
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.
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
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
This section contains questions for you to check your understanding so far. 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.
As already mentioned Git and GitHub are essential tools for every developer. So now let’s follow the next steps:
First step is to install Git. Click the Operating System you have chosen below:
Second step is to setup git. In order for Git to work properly, we need to let it know who we are so that it can link a local Git user (you) to GitHub. This is important because when we are working on a team, this allows other people to see what you have committed and who committed each line of code.
The commands below will configure Git. Be sure to enter your own information inside the quotes (but include the quotation marks)!
git config --global user.name "Your Name" git config --global user.email "email@example.com"
To enable colorful output with
git config --global color.ui auto
To verify things are working properly, enter these commands and verify that the output matches your name and email address.
git config --get user.name git config --get user.email
An SSH key is a cryptographically secure identifier. It’s like a really long password used to identify your machine. GitHub uses SSH keys to allow you to upload to your repository without having to type in your username and password every time.
First, we need to see if you have an SSH key already installed. Type this into the terminal:
If a message appears in the console containing the text "No such file or directory", then you do not yet have an SSH key, and you will need to create one. If no message has appeared in the console output, you already have a key and can proceed to step 2.3.
To create a new SSH key, run the following command inside your terminal. The
-C flag followed by your email address ensures that GitHub knows who you are.
Note: The angle brackets (
< >) in the code snippet below indicate that you should replace that part of the command with the appropriate information. Do not include the brackets themselves in your command.
Let’s see an example. If your email address is
firstname.lastname@example.org, then you would type
ssh-keygen -C email@example.com. You will see this convention of using angle brackets to indicate placeholder text used throughout this curriculum and other coding websites, so it’s good to be familiar with what it means.
ssh-keygen -C <youremail>
In this step we will need to let GitHub know what our SSH key is so that we can push our code without typing in a password every time.
So now we will navigate to where GitHub receives our SSH key.
profile picturein the top right corner
Settingsin the drop-down menu.
SSH and GPG keyson the left hand side
New SSH Keyin the top right corner.
SSH keysomething that is descriptive enough for you to remember.
SSH keyby using the
catcommand. This command will help us read the file to the console.
.pubfile extension is important in this case.
ssh-rsaand ends with your email address.
GitHubin your browser window and
keyyou copied into the key field.
Add SSH key.
You’re done! You’ve successfully added your SSH key!
In this step we will test our SSH key. Follow the directions in this article from GitHub to verify your SSH connection. If the output doesn’t correctly match up, then try going through these steps again or come to Discord to ask for help.
You have successfully completed the installations section.
You probably felt like you were in way over your head, and you probably didn’t understand much of what you were doing. That’s 100% normal. Hang in there. You can do this! And we’ve got your back.
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!
Watch the next video by
Corey Schafer for a great overview of some basic Git commands.
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.
git clone firstname.lastname@example.org:USER-NAME/REPOSITORY-NAME.gitor
git clone https://github.com/user-name/repository-name.git
git push origin main
git add .
git commit -m "A message describing what you have done to make this snapshot different"
The basic Git syntax is
program | action | destination.
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 statusis read as
git | status | (no destination).
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.
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.
git clone email@example.com:<your-github-username>/<your-repository-name>command to clone a GitHub repository onto our local machine.
git statuscommand to see any changes made since our last commit.
git addcommand to track files.
git commitcommand to commit tracked files.
git logcommand to view our commit history.
git pushcommand to send our commit to GitHub.
commit. The combination of these two commands gives you control of exactly what you want to be remembered in your snapshot.
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
commitis 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
-mflag stands for “message” and must always be followed by a commit message inside quotation marks. In this example, the commit message was
originmeans in the
git push origin maincommand?
originin 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
originto 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.
mainmeans in the
git push origin maincommand?
mainin 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
mainis the official branch in your projects where production-ready code lives.
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.
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
Read Chapter 1.1 through 1.4 in this book about version control to learn the differences between local, centralized, and distributed version control systems.
Watch this video about how Git can improve the workflow of both an individual and a team of developers.
Read 5 Git Commands You Should Know, with Code Examples and spend some time practicing on the commands described in the post.
An easy-to-read, pragmatic guide to using Git is available for free on Kindle.
Atlassian has a very thorough and well laid out Git tutorial.
For a more in-depth understanding of Git, read the free ProGit eBook.
Dangit, Git!?!: Fix common mistakes in git.
what the git: Enter a git command and have it explained to you
Oh, Shit Git!: Yes, you’ve guessed it.
This next video by
Jeff Delaney has a fast-paced overview of Git.
Duration: 12 minutes
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