This is a reference list of the most commonly used Git commands. Try to familiarize yourself with the commands so that you can eventually remember them all.
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!
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.
Note: As of October 1st, 2020, all new Git repositories create a default branch named
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 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
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).
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.
This section contains helpful links to other content. It isn't required, so consider it supplemental for if you need to dive deeper into something.
This section contains questions for you to check your understanding of this lesson.
What is the Git command used to get a full copy of an existing Git repository from GitHub?
What is the Git command used to check the status of your files?
git statusto see any changes made since your last commit.
What is the Git command used to track files with Git?
git addto track files.
What is the Git command used to commit files?
git committo commit tracked files.
What is the Git command used to view your commit history?
git logto view your commit history.
What is the Git command used to upload projects onto GitHub?
git pushto 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:
commit. The combination of these two commands gives you control of exactly what you want to be remembered in your snapshot.
- Staging: Think of
addas 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
commitas 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
-mflag stands for "message" and must always be followed by a commit message inside quotation marks. In this example, the commit message was
git push origin main.
- In Git,
originis 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
originto 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.
git push origin main.
- In Git,
mainis 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
mainis the official branch in your projects where production-ready code lives.