Git Basics

Lets learn how to track file changes using git.

Initially we gonna create a folder in desktop – book

cd Desktop
mkdir book
cd book

Then create a file page1.txt

Install Git

Then start using git in the terminal and track the file changes.

git init

git repository will be intialized, .git file will be created in the folder as a hidden file.

To view the hidden files list using the terminal we can use the following command on Power Shell terminal.

ls – Hidden

Now check view the files to be stages – git status

changes in the file page1.txt needs to be staged

Untracked file will be shown in red color.

git add

In order to add it to staging area and start tracking it,

git commit

git commit -m “complete page1”

-m refers to the commit message. Write it in present tense.

git log – to view what all commits are made

Now we can create multiple files and track it. Lets create page2.txt and page 3.txt

add contents to it also, the add to the staging using

git add .

To find difference by comparing the file changes and reverting.

git diff

git diff page2.txt –> to view the difference in the latest version and last committed version

Rollback to previous committed version

git checkout page2.txt //restores the previous version

About the Author: smartcoder

You might like

Leave a Reply

Your email address will not be published.