Workshop #2

Branches: The very basic

This workshop will makes us comfortable with branches and checkout commands.
Navigate to your repository you made in Workshop #1. The git setup is done and our project is initialized and already connected to github and we are good to go!

  • Create new folder in our project's root folder (in my case root is git-in-action). You can choose any name but also you can follow my naming to run given codes as they are. I named my folder WS1 and I navigated in WS1 folder.
  • Create a file e.g: file1.txt and type some text in it.
  • Check the repository status we should see untracked files in the address < ./ >. As we are not in git root folder, git is telling us there are some untracked filed one folder up (meaning up from the folder we are in right now).
  • Add all files in index(stage all files) and check status again. We should see file1.txt is staged. Create new branch name it WS1.
  • Then checkout to the new created branch. Commit it.
  • Check status.
  • Now add file2.txt to WS1 folder. Check status.
  • Checkout to new branch and name it WS1-child. check status
  • Add all files and then commit them. If we list the directory we will see both file1 and file2 in the folder. Now checkout to WS1 and list the files in your terminal (or just look in your file browser). You shouldn't be able to see file2.txt. Can you explain why? What will you expect to see if you checkout to master branch and list the files?
  • Modify file1.txt, stage it and commit it.
  • Checkout to WS1-child and modify file2.txt, stage and commit it too.
  • Right now our repository has 3 branches namely: master, WS1, and WS1-child. WS1 head is pointing to the last state of master and WS1-child head id pointing to the first commit of WS1 after separation from master. The graphical representation is like this:

Capture.PNG This graphical view shows that commit belongs to branch WS1 and WS1-child also have it and file2.txt belongs to WS1-child. Can you guess whether the content of file1.txt is the same in both WS1 and WS1-child or not? Explain your answer.

Workshop #2 Answers