Introduction to Git: Part 2

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 …


This content originally appeared on DEV Community and was authored by Aaron McCollum

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 <FILE NAME>.

Getting Started on a project

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

Making Changes and Committing

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:

git status

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:

git log

A Few Other Odds and Ends

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 -A will stage everything that’s unstaged in the entire project

Pushing to Github

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

Source of Learning

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.


This content originally appeared on DEV Community and was authored by Aaron McCollum


Print Share Comment Cite Upload Translate Updates
APA

Aaron McCollum | Sciencx (2021-09-17T06:28:56+00:00) Introduction to Git: Part 2. Retrieved from https://www.scien.cx/2021/09/17/introduction-to-git-part-2/

MLA
" » Introduction to Git: Part 2." Aaron McCollum | Sciencx - Friday September 17, 2021, https://www.scien.cx/2021/09/17/introduction-to-git-part-2/
HARVARD
Aaron McCollum | Sciencx Friday September 17, 2021 » Introduction to Git: Part 2., viewed ,<https://www.scien.cx/2021/09/17/introduction-to-git-part-2/>
VANCOUVER
Aaron McCollum | Sciencx - » Introduction to Git: Part 2. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/09/17/introduction-to-git-part-2/
CHICAGO
" » Introduction to Git: Part 2." Aaron McCollum | Sciencx - Accessed . https://www.scien.cx/2021/09/17/introduction-to-git-part-2/
IEEE
" » Introduction to Git: Part 2." Aaron McCollum | Sciencx [Online]. Available: https://www.scien.cx/2021/09/17/introduction-to-git-part-2/. [Accessed: ]
rf:citation
» Introduction to Git: Part 2 | Aaron McCollum | Sciencx | https://www.scien.cx/2021/09/17/introduction-to-git-part-2/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.