Workshop #2 Answers
I am using Windows, for Linux based operating system follow respective commands.
md WS1
cd WS1
echo File1 content added to the file >file1.txt
git status
git add .
git status
git branch WS1
git checkout WS1
git commit -m "file1.txt added"
git status
echo File2 content added to the file >file2.txt
git checkout -b WS1-child
git add .
git commit -m "file2.txt added"
dir
git checkout master
dir
As we list files when we are on WS1 we won't see file2.txt and when we checkout to WS1-child we will see both file1 and file2, meaning file2 is added in WS1-child and it does not exist in WS1 and by switching branches git will add or remove the files from project folder. The project folder will always have the files that are tracked in the current branch and with switching branches the file system and their content will match with current branch. Eventually when we checkout to master, neither of files will be there, because both of them are created in other branches and they are not still in the master branch.
git add .
git commit -m "file1.txt changed"
git checkout WS1-child
git add .
git commit -m "file2.txt changed too!"
type file1.txt
git checkout WS1
type file1.txt
Git is tracking files and their content as we can see file1.txt in WS1 branch has updated but WS1-child has old value. Later we will see how to update branches or discard changes.
Answers to Workshop #2