COURSE 3 – INTRODUCTION TO GIT AND GITHUB

Module 1: Introduction to Version Control

GOOGLE IT AUTOMATION WITH PYTHON PROFESSIONAL CERTIFICATE

Complete Coursera Study Guide

Last updated:

INTRODUCTION – Version Control

In this module, you’ll be introduced to the concept of version control, which will make managing and rolling back your code look super easy. You’ll learn how to differentiate between files and the tools at your disposal to make this happen. Next, you’ll be introduced to Git and how you can leverage that platform to improve your coding abilities. Once you’ve got a grasp on what Git is, you’ll install it and start using it to create and clone code repositories. Last up, you’ll deep dive into Git in order to get more familiar with the different tools and commands it has to offer.

Learning Objectives

  • Describe the concept of version control and why it is important to use
  • Utilize the diff and patch commands to automate differentiating and editing files
  • Explain what Git is and its benefits of use
  • Install Git on local machine
  • Utilize Git to create and clone repositories, add code, check the status of code, and commit code

PRACTICE QUIZ: BEFORE VERSION CONTROL

1. Your colleague sent you a patch called fix_names.patch, which fixes a config file called fix_names.conf. What command do you need to run to apply the patch to the config file?

  • diff names.conf fix_names.conf
  • patch fix_names.conf names.conf
  • patch fix_names.conf < fix_names.patch (CORRECT)
  • diff names.conf_orig names.conf_fixed > fix_names.conf

Nice job! The patch command with the file to be patched, followed by the filename of the patch, will apply it.

2. You’re helping a friend with a bug in a script called fix_permissions.py, which fixes the permissions of a bunch of files. To work on the file, you make a copy and call it fix_permissions_modified.py. What command do you need to run after solving the bug to send the patch to your friend?

  • diff fix_permissions.py fix_permissions_modified.py > fix_permissions.patch (CORRECT)
  • patch fix_permissions.py < fix_permissions_modified.py
  • patch fix_permissions.py > fix_permissions.patch
  • diff fix_permissions.py fix_permissions.diff

Awesome! The diff command will allow us to compare and apply the differences between the files.

3. The _____ commandhighlights the words that changed in a file instead of working line by line.

  • diff
  • diff -u
  • wdiff (CORRECT)
  • patch

Right on! The wdiff command highlights the words that changed in a file by color, in addition to working line by line.

4. How can we choose the return value our script returns when it finishes?

  • Using the exit command from the sys module (CORRECT)
  • Use the patch command
  • Use the diff command 
  • Use meld

Great work! A script can use sys.exit to finish processing and return the number passed as an argument as the script’s return code.

5. In addition to the original files, what else do we need before we can use the patch command?

  • Diff file (CORRECT)
  • exit command of the sys module
  • Version control
  • Full copy of the new files

Woohoo! We need to use the patch command with the diff file to apply new changes to the original file.

6. What’s the goal of a version control system?

  • To make sure that our code has no bugs
  • To keep track of changes made to our files (CORRECT)
  • To have backup copies of our code
  • To store code, images, configuration, and videos

Right on! A version control system allows us to keep track of when and who did what changes to our files. Those can be code, configuration, images, or whatever else we need to track.

7. What’s the goal of the diff tool?

  • To keep track of changes to our files
  • To check if our changes make sense
  • To highlight new lines in Python filesTo show the differences between two files (CORRECT)

You got it! The diff tool shows all the differences between any type of file. By highlighting what’s changed, it helps us understand the changes and see how the files have been modified.

8. What does the patch command do?

  • It generates a file with the differences between two files.
  • It shows the changes made in a directory of files.
  • It redirects the contents of a file into standard input.
  • It applies the changes contained in a diff file to another file. (CORRECT)

Right on! While diff is the command that generates the difference between two files, patch is the command that applies those differences to the original file.

9. We’ve prepared a diff file with the changes that need to be applied to the script. What does our colleague need to do now?

  • Look at the changes in the diff file and manually modify the original file with those same changes.
  • Run diff disk_usage.diff disk_usage.py.
  • Ask us to send them the full file, not just the diff file.
  • Run patch disk_usage.py < disk_usage.diff. (CORRECT)

You nailed it! To automatically apply changes to a file, we need to run the patch command on the file that we want to modify with the diff file as input.

PRACTICE QUIZ: VERSION CONTROL SYSTEMS

1. How can a VCS (Version Control System) come in handy when updating your software, even if you’re a solo programmer? Check all that apply.

  • Git retains local copies of repositories, resulting in fast operations. (CORRECT)
  • If something breaks due to a change, you can fix the problem by reverting to a working version before the change. (CORRECT)
  • Git relies on a centralized server.
  • Git allows you to review the history of your project. (CORRECT)

Awesome! Git’s distributed architecture means each person contributing to a repository retains a full copy of the repository locally.

Nice job! With version control, if something goes wrong, we can fix it immediately and figure out what happened later.

Right on! 

2. Who is the original creator and main developer of the VCS (Version Control System) tool Git?

  • Bill Gates
  • Guido van Rossum
  • Linus Torvalds (CORRECT)
  • James Gosling

Nailed it! Linus Torvalds developed Git in 2005 to better facilitate the process of developing the Linux kernel with developers across the globe.

3. _____ is a feature of a software management system that records changes to a file or set of files over time so that you can recall specific versions later.

  • A repository
  • sys.exit()
  • Version control (CORRECT)
  • IDE

Right on! A version control system keeps track of the changes that we make to our files.

4. A _____ is a collection of edits which has been submitted to the version control system for safe keeping.

  • IDE
  • version control system
  • commit (CORRECT)
  • repository

Awesome! We call the collection of edits we are making at one time a commit.

5. Within a VCS, project files are organized in centralized locations called _____ where they can be called upon later.

  • commits
  • repositories (CORRECT)
  • IDE
  • yum

Excellent. A repository is a central location in which data is stored and managed.

6. What does a version control system do?

  • It groups all related code.
  • It explains why a change was made.
  • It keeps track of changes we do to our files. (CORRECT)
  • It prevents us from changing files by mistake.

Correct!Spot on! By keeping track of the changes that we make to our files, a VCS lets us know when a file changed, who changed it, and also lets us easily roll back those changes.

7. Why is a version control system useful, even if it’s used only by a single person? Check all that apply.

  • Seeing the history of the changes helps us understand what changed and why. (CORRECT)
  • Tracking code in a VCS ensures that it’s bug free.
  • Tracking changes allows for easy rollbacks when a problem is detected. (CORRECT)
  • Storing files in a VCS avoids the need for any kind of backups.

You got it! One of the main benefits of a VCS is that you can see the history of how files changed and understand what changed at each step and what motivated the change.

Right on! By having each change tracked in the VCS, it’s very easy to go back to previous versions when an issue with a change is discovered.

8. What characteristics make Git particularly powerful? Check all that apply.

  • It was created by Linus Torvalds in 2005.
  • It’s a distributed VCS, which means that each developer has a full copy of the repository. (CORRECT)
  • It’s maintained by a team of distributed developers.Repositories can be used by as many developers as needed. (CORRECT)

You nailed it! Because each contributor to a Git repo has a full copy of the repository, they can interact with the tracked files without needing a coordinating server. In turn, this improves collaboration.

Right on! Because of the way Git was designed, repositories can be useful for any number of developers, from one to thousands.

9. What’s the command that you need to run to check what version of Git is currently installed in your computer?

  • git init
  • git show version
  • git commit
  • git –version (CORRECT)

You got it! Running git –version in your computer will display the currently installed version of Git (if Git is installed on your computer).

PRACTICE QUIZ: USING GIT

1. Before changes in new files can be added to the Git directory, what command will tell Git to track our file in the list of changes to be committed?

  • git status
  • git add (CORRECT)
  • git commit 
  • git init

Right on! git add will add a file to the staging area and mark it for tracking.

2. Which command would we use to review the commit history for our project?

  • git clone
  • git status (CORRECT)
  • git config -l
  • git log

Awesome! git log will give us information about the author of each commit, its timestamp, and each commit message.

3. What command would we use to make Git track our file?

  • git clone
  • git status
  • git add (CORRECT)
  • git log

Great work! git add is used to make git mark our file as tracked.

4. Which command would we use to look at our config?

  • git clone
  • git status
  • git config -l (CORRECT)
  • git log

Great work! git config -l is used to check the current user configuration.

5. Which command would we use to view pending changes?

  • git clone
  • git status (CORRECT)
  • git config -l
  • git log

Woohoo! git status is used to retrieve information about changes waiting to be committed.

6. What are the git directory and the working tree?

  • The git directory stores configuration settings and the working tree stores the history of the files.
  • The git directory is copied to the computer and the working tree stays in the remote repository.
  • The git directory is a sandbox for changing the files and the working tree contains old versions of the files.
  • The git directory contains all the changes and their history and the working tree contains the current versions of the files. (CORRECT)

Awesome! The git directory acts as a database for all the changes tracked in Git and the working tree acts as a sandbox where we can edit the current versions of the files.

7. What do we need to do after modifying a file tracked by Git?

  • We need to stage the file, so that the changes will be included in the next commit. (CORRECT)
  • We need to commit the file, so that the changes will become part of the staging area.
  • We need to add the file to the Git directory.
  • We need to change to a different working tree.

You nailed it! After modifying a file, we need to stage those changes and then commit them afterwards.

8. When committing new files or changes with git commit, the user is asked to provide a commit message. What will happen if an empty commit message is entered?

  • It will make it difficult to track bugs without commit messages.
  • The info shown with the git log command will show no commit message.
  • The commit will be aborted. (CORRECT)
  • The commit will ignore untracked files or files that weren’t staged.

Nice work! You can’t commit with an empty commit message.

9. What should your commit message look like?

  • A jumble of words
  • A description of no more than 50 characters
  • A short description of the change (up to 50 characters), followed by one or more paragraphs giving more details of the change (if needed). (CORRECT)
  • Always write as much as you can about the changes.

Awesome! You want your message to contain all relevant information without being confusing.

INTRODUCTION TO GIT

1. What do you need to do before you install Git on your Linux VM? 

  • Make sure that you have a fresh index of the packages available to you. (CORRECT)
  • Check which version of Git will be installed.
  • Initialize a repository.
  • Create a directory.

Correct

2. What does the command git –version do? 

  • Installs Git
  • Updates Git to the latest version
  • Uninstalls Git
  • Checks if Git is installed and shows the version (CORRECT)

Correct

3. When viewing the status of files of the project, where are the files listed that Git is not yet tracking? 

  • They are not listed in the status.
  • Under “Untracked files” (CORRECT)
  • Under “Uncommitted files”
  • Under “Working files”

Correct

4. What is the command for moving files to the staging area? 

  • git commit
  • git add (CORRECT)
  • git move
  • git config

Correct

5. What command would you use to add the commit message “Revisions complete” at the same time you enter a git commit command?

  • git commit -m [Revisions complete]
  • git commit “Revisions complete”
  • git commit -m “Revisions complete” (CORRECT)
  • git commit -cm “Revisions complete”

Correct

6. What command will allow you to view all the commits?

  • git log (CORRECT)
  • git updates
  • git commit -s
  • git status

Correct

7. Which of the following best describes Git? 

  • A version control system (CORRECT)
  • A repository
  • A VM instance
  • A database

Correct

8. What is the first step to create a new repository in Git? 

  • Clone an existing repository using git clone
  • Initialize a new repository using git init (CORRECT)
  • Fork a repository from GitHub using git fork
  • Create a new branch in a repository using git create

Correct

9. The git config command has several functions. Which of the following is one of them?

  • To creates a .git subdirectory in the current working directory
  • To change the user email associated with future Git commits (CORRECT)
  • To change the user email associated with previous Git commits
  • To create a HEAD file which points to the currently checked out commit.

Correct

10. What is the best description of a repository from the choices below? 

  • A repository is a location where all the files of a particular project are stored. (CORRECT)
  • A repository is all changes whether they have been staged or not. 
  • A repository is a collection of Virtual Machines.

Correct

11. What is the first step to install Git on a Linux machine? 

  • Run sudo apt install git in the terminal (CORRECT)
  • Create a GitHub account
  • Run git –version in the terminal
  • Download Git from the official website

Correct

12. What is the best definition below of the staging area? 

  • A directory without a GIt repository
  • Where files are not yet tracked by Git
  • A repository of Git commits
  • Where files are gathered and prepared for Git before committing them (CORRECT)

Correct

13. After you have made a commit, what command can you use to look at the changes?

  • git status
  • git add
  • git diff (CORRECT)
  • git changes

Correct

14. What is the purpose of the git config command? 

  • To create a new branch in the repository
  • To display the current status of the repository
  • To stage changes for the next commit
  • To configure global or repository-specific settings (CORRECT)

Correct

15. What will the command nano README return?

  • A text file named README (CORRECT)
  • A repository named README
  • A status report named README
  • A directory named README

Correct

16. When using the -m flag to add the commit message at the same time you enter a git commit command, what happens if multiple -m flags are given to the command?

  • The first commit message is saved.
  • The commit message values are concatenated as separate paragraphs. (CORRECT)
  • The last commit message is saved.
  • The commit message values are combined into a single paragraph.

Correct

17. The git init command has several functions. Which of the following is one of them?

  • To convert an existing, unversioned project to a Git repository (CORRECT)
  • To override an existing .git configuration.
  • To configure Git
  • To create a new directory

Correct

18. When viewing the status of files of the project, where are the files listed have been moved to the staging area using the git add command? 

  • Under “Changes to be tracked”
  • Under “Changes to be saved”
  • They are not listed in the status.
  • Under “Changes to be committed” (CORRECT)

Correct

19. What is the result of using the git commit command? Select all that apply. 

  • It changes the configuration of the repository.
  • It changes the status of the repository.
  • A snapshot is captured of the project’s currently staged changes. (CORRECT)
  • It stores the current contents of the index in a new commit along with the commit message. (CORRECT)

Correct

20. What will the git log command display (if you have not used any options to limit the output of this command)?

  • The status of the repository
  • A unique commit ID at the top of each commit (CORRECT)
  • The commit history of the repository (CORRECT)
  • The commit message (CORRECT)

Correct

21. What is Git primarily used for? 

  • Creating websites
  • Designing graphics
  • Managing databases
  • Version control (CORRECT)

Correct

22. What command will display changes that have been staged, changes that haven’t been staged, and files that aren’t tracked by Git.? 

  • git status (CORRECT)
  • git config
  • git init
  • git commit

Correct

23. After you enter a commit message, how do you save that message?

  • Press Ctrl-o and Enter key. (CORRECT)
  • Use the git message command.
  • Use the git commit command.
  • Use the git add command.

Correct

24. Using the git diff command will let you see changes made to the file. How can you spot these changes?

  • Lines with new additions start with “add”, lines with replacements/removals start with “subtract”.
  • Lines with new additions end with a plus (+) sign, lines with replacements/removals end with a minus (-) sign.
  • Lines with new additions have the latest version number, lines with replacements/removals shave earlier version numbers. 
  • Lines with new additions start with a plus (+) sign, lines with replacements/removals start with a minus (-) sign. (CORRECT)

Correct

CONCLUSION – Introduction to Version Control

In conclusion, this module serves as a comprehensive guide to version control, offering valuable insights into code management and rollback procedures. By learning to differentiate between files and employing effective tools, you have laid the groundwork for efficient code organization. The introduction of Git further enriches your coding capabilities, providing a powerful platform for version control.

As you progress through the module, you not only acquire a solid understanding of Git but also actively apply it by installing and utilizing the platform for creating and cloning code repositories. The final segment deepens your knowledge of Git, exploring its diverse tools and commands to enhance your overall familiarity with this indispensable system. Armed with these skills, you are well-equipped to navigate the intricacies of version control and elevate your coding proficiency.