Study Guide - Chap27: Controlling Versions with Git Flashcards
(10 cards)
1- Which of the following is true concerning version control? (Choose all that apply.)
- Provides a common place to merge and store files
- Requires filenames to contain version numbers
- May be distributed or nondistributed
- Helps to protect files from being overwritten
- Can deal with files other than programs
- Provides a common place to merge and store files
- May be distributed or nondistributed
- Helps to protect files from being overwritten
- Can deal with files other than programs
Options A, C, D, and E all contain true statements concerning version control and are therefore correct answers. Version control does not require filenames to contain version numbers, and thus, option B is an incorrect choice.
2- Conceptually Git is broken up into distinct areas. Which of the following is one of those areas? (Choose all that apply.)
- Blob
- Local repository
- Remote repository
- Index
- Working directory
- Local repository
- Remote repository
- Index
- Working directory
Conceptually Git is broken up into distinct areas, which are the working directory, the staging area (also called the index), the local repository, and the remote repository. Therefore, options B, C, D, and E are correct answers. A blob is another name for an object stored by Git in the .git/objects/ directory. Thus, option A is an incorrect choice.
3- Which of the following are steps needed to set up a Git environment for the first time? (Choose all that apply.)
- Create a working directory.
- Initialize the .git/ directory in the working directory.
- Set up the local repository options.
- Add files to the staging area when ready.
- Establish the remote repository.
- Create a working directory.
- Initialize the .git/ directory in the working directory.
- Set up the local repository options.
- Establish the remote repository.
The steps listed in options A, B, C, and E are all involved in setting up a Git environment for the first time. Adding files to the staging area is done after the environment is set up and files have been created in the working directory. Therefore, option D is the only incorrect choice.
4- Natasha has created her working directory for a new project. What should she do next to set up her Git project environment?
- Issue the mkdir command.
- Enter the git config –list command.
- Set up her GitHub repository.
- Enter the git init command.
- Start creating her program files
Enter the git init command.
Because Natasha is setting up her Git environment, she should next create and initialize the .git/ directory in her working directory, via the git init command. Therefore, option D is the correct answer. The mkdir command is employed to create the working directory, which is already done, so option A is a wrong answer. The git config –list command shows configuration data, which should be done after the .git/ directory is initialized, so option B is a wrong choice. While Natasha could set up her GitHub repository now, it is not the best next step, so option C is a wrong answer. Starting to create program files is an incorrect choice since Natasha is still setting up her Git environment. Therefore, option E is incorrect.
5- When setting his Git configuration options, Bruce employs the –global option on his commands. What does this mean?
- The configuration information is stored on GitHub.
- The configuration information is stored in ~/.gitconfig.
- The configuration information is stored in the working directory’s .git/config file.
- The configuration information is stored in the working directory’s .git/index file.
- The configuration information is stored in the working directory’s .git/objects directory.
The configuration information is stored in ~/.gitconfig.
Since Bruce employed the –global option when setting his Git configuration options, the information is stored in the global ~/.gitconfig file. Therefore, option B is the correct answer. This Git configuration information is not stored on GitHub, and GitHub may not even be employed as the remote repository in this case, so option A is a wrong answer. The working directory’s .git/config file is the local file, not the global one, so option C is a wrong choice. The .git/index file and .git/objects directory do not store this type of data, so options D and E are incorrect choices.
6- Bruce has set up his Git environment and finished working on his new GreenMass.sh script. What should he do next?
- Add the script to the staging area.
- Issue the git init command.
- Commit the script to the local repository.
- Issue the git log command.
- Commit the script to the remote repository.
Add the script to the staging area.
The next step Bruce should take is to add his new script to the staging area (index) via the git add GreenMass.sh command. Therefore, option A is the correct answer. The git init command is used to initialize the .git/ directory in the working directory and is part of setting up the Git environment, so option B is a wrong answer. The script cannot yet be committed to the local repository because it has not been added to the staging area. Thus, option C is an incorrect choice. The git log command shows the commit history and is not appropriate at this point, so option D is a wrong answer. The script cannot be committed to the remote repository until it is committed to the local repository. Therefore, option E is an incorrect choice.
7- There are 25 files in Natasha’s working directory and she only wants to add 22 of them to the index. She plans on using the git add . command to be efficient. What should she do?
- Move the three files out of her working directory.
- Add the 22 files individually via the git add command.
- Create a new working directory for the three files.
- Add the three files’ names to a .gitignore file.
- Temporarily delete the three files.
Add the three files’ names to a .gitignore file.
Natasha is being efficient by employing the git add . command, which will add all the files within the working directory to the staging area (index). To stay efficient, she should create a .gitignore file in the working directory and add the names of the three files that she wishes to keep out of the index to that file. This will prevent them from being added. Therefore, option D is the correct answer. While Natasha could move the three files out of her working directory, that is a sloppy and inefficient choice, so option A is a wrong answer. She also could add the 22 files individually to the index, but that too is very inefficient, as is creating a new working directory for the three files. Thus, options B and C are incorrect answers. Temporarily deleting the three files would force Natasha to re‐create them after the other files are added to the index. This too is sloppy, and therefore option E is an incorrect choice.
8- Natasha has completed her open source project, which is set to be released to the public today. She has moved the files to the staging area, committed her work to the local repository, and configured the remote repository’s address. What is her next step?
- Go home and relax. She deserves it.
- Clone the remote repository to her local system.
- Push her project to the remote repository.
- Pull her project from the remote repository.
- Use the remote add origin URL command.
Push her project to the remote repository.
Natasha is ready to push her project to the remote repository, so option C is the correct answer. While she may go home and relax later, if the project is released to the public, she must upload it to the remote repository first. Therefore, option A is a wrong answer. Cloning a remote repository is done when someone wants all the project files as well as the VCS history. In this scenario, Natasha already has that data, so option B is a wrong choice. Since the project is complete, there is no need to pull down any files from the remote repository. Therefore, option D is also an incorrect answer. The remote add origin URL command is used to configure the remote repository’s address (URL), which Natasha has already accomplished. Thus, option E is an incorrect choice.
9- Which of the following commands allows you to switch to a new Git branch called testing?
- git branch testing
- git ls-tree –name-only -r testing
- git branch
- git commit -m “testing”
- git checkout testing
git commit -m “testing”
The git checkout testing command will allow you to switch to a new Git branch called testing. Thus, option E is the correct answer. The git branch testing command creates a new branch called testing instead of switching to it. Thus, option A is a wrong answer. The command in option B allows you to view the names of any files managed by the testing branch, so it is an incorrect answer. The git branch command shows you the current branches within this project and designates which one is current via an asterisk, but it does not allow you to switch branches. Thus, option C is an incorrect answer. The command in option D will perform a commit to the local repository and add a comment of testing to the log file. Therefore, option D is also an incorrect choice.
10- Tony created a new branch of the StoneTracker project called report. He has completed and tested his work. He now needs to merge it with the StoneTracker project’s master branch. After switching branches to the master branch, what command should he employ?
- git merge master
- git merge report
- git rebase master
- git rebase report
- git checkout master
git merge report
The git merge report command will merge the report branch into the master branch as desired, so option B is the correct answer. The git merge master command will attempt to merge the master branch into another branch, but since Tony is already in the master branch, this will not work (and is not desired), so option A is a wrong answer. The rebase arguments will attempt to perform a rebase instead of a merge. Thus, options C and D are incorrect answers. The git checkout master command was already used by Tony to reach the master branch, and thus option E is an incorrect choice.