Git/GitHub
Nov 2 · 4 min read
Git Part 1
What is git?
Git is Version Control System (VCS) for tracking changes in computer files.
What does this mean?
- It’s a system that records changes to our files over time.
- We can recall specific versos of those files at any given time.
- Many people can easily collaborate on a project and have their own version of project files on their computer.
How Git works
Repositories (repo’s)
- A repo is a container for a project you want to track with Git (e.g a website project).
- Can have many different repo’s for many different projects on your computer.
- It is like a project folder which Git tracks the contents for us.
- So where ever the .git file is.
For example:
- Say we have a folder named My Project.
- This My Project folder is a repo and is being tracked by git because there is the .git file in it.
- It will track all the changes in the My Project repo.
- If .git file was in the img folder it will only track changes that are made in the img folder.

Staging Files
- Say I have modified the index.html file and I want to commit the changes I have made, if I commit now nothing will be commit because nothing is in the staging area.
- We need to add it to the staging area before we commit.

- The git status command will show us which files have changed and which files are in the staging area.
- If the file name is in red it means the file has been changed but is not added in the staging area.
- To add files to the staging area we can use git add command with the file name behind git add command to add it to the staging area
- ex. git add index.html.
- When the file is added to the staging area the file name will change to green.
- If you want to remove any files from the staging area you can use the command git rm — cached file name to unstage any files in the staging area.
- ex. git rm — cached index.html.



Making commits
- Commits are like save points that tracks our work.
- We can go back to each commit to see what the code is like.


Now how do we commit?
- We use the git commit command with a message that describes what you did.
- ex. git commit -m “added index and styles files”

What do we do if we want to see our commit history?
- We use git log command to see our commit history.

- If you want to see a more simplified version of the commit history you can use the git log — — oneline command.

Undoing Commits

There are three commands that we can use to undo commits.
The commands are color coded in order of danger green being the safest to red being unsafe.
Checkout commit
- Checkout commit is read only
Revert commit
- Allows us to undo a particular commit.
- Git revert does not delete the selected commit but undo all the changes made in the particular commit.
Reset commit
- Permanently go back to a particular commit and any commit that was made after the commit you go back to is deleted
How do we use these commands
Git checkout
- Use git checkout (unique commit id we want to checkout)

Git revert
- Git revert (unique commit id we want to revert to)
- :wq (to get out of the screen in first pic)
- Git revert will add a new commit that reverts the selected commit we want to revert


Git reset
- Git reset (unique commit id that we want to reset to)
- As you can see all the commits that came after af6b84c has been deleted

Will be back with Part 2!
