04 - Git - Exercise 2
Task 1 - Creating a git repo
Open GitBash and navigate to your folder of choice.
Create a new directory called
localRepo
.Navigate into this newly created directory.
Turn it into a git repository by typing
git init
.Check that the repository has been initialised - use the
ls -a
command to see all the hidden files, you should now see.git
folder.Create a new file in this directory -
touch file1.txt
.Check if git recognised any change being made -
git status
.Stage the file -
git add .
Check how the status changes.
Commit your change with a sensible message :
git commit -m "my first commit"
Check the log :
git log
. Can you see the commit history?
Task 2 - Undoing changes
Open GitBash if closed and navigate to your
localRepo
created above.Create another file -
file2.txt
.Stage it.
Now un-stage it -
git rm --cached file2.txt
Delete the
file2.txt
.Change the content of the
file1.txt
using vi.Undo those changes by checking the file out -
git checkout file1.txt
.