Lesson 263 – Complete 2020 Web Development Bootcamp

Lesson 263 – Using GIT and the Command Line

To initialize git on a directory using the Terminal you cd to the directory and type:

git init

The directory you are using git on is called the “working directory”.

To see what files are in your git staging area you type:

git status

In order to add files to the git staging area and start tracking changes to the file, you type “git add” and the file name. So to add a file labelled “chapter1.txt” you would type:

git add chapter1.txt

To commit the file under git version control, you type:

git commit

You should add a message to the commit to help keep track of what changes the commit relates to. You add a message to a git commit by adding “-m” and the message text to the line “git commit”. So a git commit with a message looks like this:

git commit -m "Complete Chapter 1"

By convention, git commit messages are written in the present tense.

To see the commits you have made, you use the git log command by typing:

git log

The git log shows you the date and author of the commit. Each commit also has a unique hash which identifies that particular commit. An example of a commit hash is:

commit a239e52278bcae2e85b4b99ecbed44e40a2bdaec

To add multiple files to the staging area at one time, you can type:

git add .

To see the differences between the current version of a file and the last version saved by git you can use the git diff command –

git diff chapter3.txt

To rollback to the previous version of a file, you can use the git checkout command. So –

git checkout chapter3.txt