Exercise 2 Basic Git Commands
Exercise 2 Basic Git Commands
In this exercise you will get familiar with some basic Git commands. At the end of
this exercise you will be able to:
<!DOCTYPE html>
<html>
<head></head>
<body>
<h1>This is a Header</h1>
</body>
</html>
Go to the git-test folder in your cmd window/terminal and type the following at
the prompt to initialize the folder as a Git repository:
git init
1
Checking your Git repository status
Type the following at the prompt to check your Git repository's status:
git status
git add .
git commit -m "first commit"
git log --oneline
<!DOCTYPE html>
<html>
<head></head>
<body>
<h1>This is a Header</h1>
<p>This is a paragraph</p>
</body>
</html>
2
Add a sub-folder named templates to your git-test folder, and then add a file
named test.html to the templates folder. Then set the contents of this file to
be the same as the index.html file above.
Then check the status and add all the files to the staging area.
Then do the second commit to your repository
Now, modify the index.html file as follows:
<!DOCTYPE html>
<html>
<head></head>
<body>
<h1>This is a Header</h1>
<p>This is a paragraph</p>
<p>This is a second paragraph</p>
</body>
</html>
Now add the modified index.html file to the staging area and then do a third
commit.
To check out the index.html from the second commit, find the number of the
second commit using the git log, and then type the following at the prompt:
git checkout <second commit's number> index.html
3
Resetting the Git repository
To discard the effect of the previous operation and restore index.html to its
state at the end of the third commit, type:
git reset HEAD index.html
git checkout -- index.html
You can also use git reset to reset the staging area to the last commit without
disturbing the working directory.
Conclusions
At the end of this exercise you should have learnt some basic Git commands.
Experiment with these commands until you fully understand how to use Git.