This is part 2 of the introduction to Git. You can check out Part 1 of the Introduction to Git here, which goes over the history of Git and the theoretical way it works. In this post, it will be more brief with a step-by-step process on using Git.
As a quick note: anything inside these symbols (< and >) is meant to convey unique inputs, and the < and > symbols are not to be actually typed in the terminal.
Git’s main syntax is as follows: program | action | destination (
git add <FILE NAME> as an example). You will see below this syntax play out in real time.
Git is the program,
add is the action, and the destination of the action is on the
When you create a new repository in Github, it will provide the SSH key for you to link to your local disk’s Git program. You can copy the link, then use:
git clone <URL Link>
This will clone your program onto your local computer for you to work on. You can then use the
cd command to change to the project’s directory and start adding files, and then you can use the code command to open the files up in VS Code.
>cd <REPO NAME> >touch index.html >touch style.css
Once files are added to your project in Git, they are either staged or not staged. Not staged means they will not be committed when you start your next commit push, while staged means they are ready to be committed. If a file is not staged, it will by default show up as red in your console, and files that are staged will show up as green. You can check the status of each file by typing:
If a file is not staged but is ready to be staged, you can type the following command:
git add <FILE NAME>(you can list multiple file names separated by spaces)
Once you are ready to commit your staged files, you can use the following command:
git commit -m "COMMIT MESSAGE"(the -m flag is a message flag for note-taking)
At any point, if you would like to see a record of what you did, you can use the following command:
When you change a file you are working on that is part of your local project in Git, it will automatically change to the “modified” status when you use the git status command, since it’s being tracked by Git.
git add <FILE>will stage the individual file
git add .will stage everything in the current directory
git add -Awill stage everything that’s unstaged in the entire project
When you are ready to push your changes and commits to Github, you can use the following command. This one is a little slower since you are connecting with a remote server:
git push origin main
I have been learning Git on The Odin Project and have really enjoyed it. Their explanations are far better than mine and that’s a great resource if you are like me and starting out.
Also the Git website features a full version of the book “Pro Git” by Scott Chacon and Ben Straub, which I found very useful for a lot of information.