Learning Objectives


In the Asynchronous Lecture


In the Synchronous Lecture


If you have any questions while watching the pre-recorded material, be sure to write them down and to bring them up during the synchronous portion of the lecture.




Synchronous Materials




Asynchronous Materials


The following tabs contain pre-recorded lecture materials for class this week. Please review these materials prior to the synchronous lecture.

Total time: Approx. 1 hour and 12 minutes


Version Control with Git/Github





Git using the Commandline


Code from the video

# Here are the commandline commands we used in the video
cd <directory-path> # Set a working directory
ls                  # List all files in the working directory
l                   # List all files + hidden files in the working directory
touch <file-name>   # To create a file

# Here are the git commands that we used in the video 
git init            # to initialize a git repository
git status          # to see which files we've staged and git is tracking
git add <file-name> # to add a file to the staging area (to be committed)
git commit -m ""    # To create a snap shot of the project (i.e. of all staged files)
git log             # To look up the timeline of commits
git log --reflog    # To look up the entire timeline (even when we've gone back in time)
git checkout <hash-code> # To go back to a previous moment in the project timeline. 



Checking out & Branching


Code from the video

# Here are the git commands we used in this video
git commit              # To commit staged changes
git checkout <hash>     # To checkout a prior snap shot in the project
git branch <name>       # To create a new named branch
git branch              # To list off all existing branches
git merge <branch-name> # To merge one branch with the current branch



Tagging Commits


Code from the video

# Here are the git commands we used in this video
git commit              # To commit staged changes
git checkout <hash>     # To checkout a prior snap shot in the project
git branch <name>       # To create a new named branch
git branch              # To list off all existing branches
git tag <tag-name>      # To generate a tag for the specific commit



Merge Conflicts


Code from the video

# Here are the git commands we used in this video
git commit                 # To commit staged changes
git checkout <branch-name> # To checkout branch
git merge <branch-name>    # To merge one branch with the current branch



Git Cheat Sheet

Overwhelmed? No worries. git (like most languages) is something you learn best by doing. But here is a cheatsheet to help you along the way. Remember, when programming, cheating is okay! Use Google, use cheatsheets, reference in-class examples — do whatever it takes to learn.




Feedback

The following survey asks you quick questions regarding the usefulness of the asynchronous lecture materials. Feedback will be used to modify aspect of the asynchronous materials moving forward.




Practice


These exercises are designed to help you reinforce your grasp of the concepts covered in the asynchronous lecture material.


_

Question 1


Create a folder called “Practice” on your desktop. Next, use the commandline to navigate to that folder. Finally, initialize a git repository in that folder.


_

Answer

cd ~/Desktop/Practice # Navigate to the Practice/ folder you created
git init # Initialize a git repository

Question 2


Using the git repository that you created in Question 1. Do the following:

  1. Create a simple .txt file using the touch command (or make this file yourself on your compute). Call the file test_file.txt. Add a sentence to this file and then save;
  2. Add that file to the staging area;
  3. Check to see if the file is staged using git status;
  4. Commit that file and add the message “My first commit”;
  5. Now update the file (i.e., make some change to it) and stage and commit that change;
  6. Look at your git log to see the two commits you made.


_

Answer

# (1) Create a file
touch test_file.txt # Create the file and open it up and add a sentence
# Here is another way to create a file with the sentence included 
echo "This is a file" > test_file.txt

# (2) Add file to the staging area
git add test_file.txt

# (3) Double check file is staged
git status

# (4) Commit file
git commit -m "My first commit"

# (5) Update file and commit. 
echo "This is a file. New information" > test_file.txt
git add test_file.txt
git commit -m "Updated test_file.txt"

# (6) Look at git log to see commits.
git log

Question 3


Using the git repository from Q1 & Q2, let’s practice branching and managing merge conflicts.

  1. Create and checkout a new branch called “new”
  2. Make a change test_file.txt and commit.
  3. Check out the master branch.
  4. Make a change test_file.txt and commit; Make sure that change is to the same line as you change in step 2. Make sure the change differs from what you did in step two.
  5. Now merge the new and master branches.
  6. Manually resolve the git conflict and then commit the resolved version.
  7. Look at your git log to see the timeline of changes.


_

Answer

# (1) create and checkout new branch
git checkout -b "new" 

# (2) Make a change `test_file.txt` and commit. 
echo "This is a file. New information. More info" > test_file.txt
git add test_file.txt
git commit -m "Made change to new branch"

# (3) Check out the `master` branch.
git checkout master

# (4) Make a change `test_file.txt` and commit
echo "This is a file. New information. The cat is black." > test_file.txt
git add test_file.txt
git commit -m "Added material to test_file"

# (5) Now merge the `new` and `master` branches.
git merge new

# (6) Manually resolve the git conflict and then commit the resolved version. 
# Do this by openning the file and manually correcting the discrepancy. 
git add test_file.txt
git commit -m "managed the merge conflict"

# (7) Look at your git log to see the timeline of changes.
git log
 

The following materials were generated for students enrolled in PPOL564. Please do not distribute without permission.

ed769@georgetown.edu | www.ericdunford.com