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:
main. You can do so by running:
git config --global init.defaultBranch main
mainsee GitHub’s Renaming Repository.
git clonefollowed by the URL you copied in the last step. The full command should look similar to
git clone email@example.com:USER-NAME/REPOSITORY-NAME.git.
cdinto the new git_test folder that was downloaded and then enter
git remote -vin your command line. This will display the URL of the repository you created in GitHub, which is the remote for your local copy. You may have also noticed the word origin at the start of the
git remote -voutput, 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_testfolder called “README.md” with the command
git statusin your terminal. In the output, notice that your README.md file is shown in red, which means that this file is not staged.
git add README.md. This command adds your README.md file to the staging area in Git.The staging area is part of the two step process for making a commit in Git. Think of the staging area like a “waiting room” for your changes until you commit them. Now, type
git statusagain. In the output, notice that your file is now shown in green, which means that this file is now in the staging area.
git commit -m "Add README.md"and then type
git statusonce more. The output should now say, “nothing to commit, working tree clean”, indicating that your changes have been committed. Don’t worry about the
upstream is gonemessage you may see, this is totally normal and only showing because your cloned repository currently has no branches. It will be resolved once you have followed the rest of the steps in this project.
git logand 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.
hello_world.txt. In the terminal, type
git status, and notice
hello_world.txtis not staged.
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 add README.md.
git statuswill 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.
git add ., where the full stop means to add all files in the current directory that are not staged. Then, type
git statusonce more, and everything should now be in the staging area. (Note: You can use
git add -Ato add ALL unstaged files to the staging area within the repository)
git commit -m "Add hello_world.txt and edit README.md". Then, type
git statusonce again, which will output “nothing to commit”.
git log. You should now see two entries.
Finally, let’s upload your work to the GitHub repository you created at the start of this tutorial.
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:
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).
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.
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 Odin projects.
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!
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. If you’re having trouble answering the questions below on your own, review the material above to find the answer.
git push origin main.
git push origin main.