Free Version Control and Git Fundamentals Questions and Answers — Questions and Answers
Question 1: What is the primary purpose of using Git?
- Designing user interfaces
- Deploying applications
- Version control and collaboration (Correct answer)
- Writing documentation
Correct answer: Version control and collaboration
Git is a distributed version control system (DVCS) designed to track changes in source code and other files over time. Its primary purpose is to enable multiple developers to collaborate on a project efficiently, managing different versions of the codebase and preventing conflicts. This ensures a complete history of all modifications and facilitates teamwork.
Question 2: Which Git command is used to check the current status of your working directory and staging area?
- git check
- git status (Correct answer)
- git log
- git commit
Correct answer: git status
The `git status` command provides a summary of the current state of your working directory and staging area. It shows which files have been modified, which are staged for the next commit, and which untracked files are present. This command is essential for understanding what changes are pending and preparing for your next commit.
Question 3: Which file in a Git repository is used to avoid tracking specific files?
- README.md
- .gitattributes
- .gitignore (Correct answer)
- config.json
Correct answer: .gitignore
The `.gitignore` file is used to specify intentionally untracked files that Git should ignore. This prevents temporary files, build artifacts, personal configurations, or sensitive data from being accidentally committed to the repository. By listing these files, you keep your repository clean and focused on essential project files.
Question 4: What does the `git commit` command do?
- Saves changes to the cloud
- Pushes changes to remote
- Records changes in the repository (Correct answer)
- Deletes previous commits
Correct answer: Records changes in the repository
The `git commit` command takes the changes that have been staged (added to the staging area using `git add`) and permanently records them as a new snapshot in the repository's history. Each commit includes a unique ID and a commit message describing the changes. This creates a point to which you can revert if needed, preserving the project's evolution.
Question 5: Which command initializes a new Git repository?
- git new
- git create
- git start
- git init (Correct answer)
Correct answer: git init
The `git init` command creates a new, empty Git repository or reinitializes an existing one in the current directory. This command sets up the necessary Git internal data structures, including the `.git` directory. Once initialized, you can start tracking changes for your project within that directory.
Question 6: What is the function of a Git branch?
- Track deleted files
- Manage collaborators
- Separate lines of development (Correct answer)
- Display commit history
Correct answer: Separate lines of development
Git branches allow developers to diverge from the main line of development to work on new features, bug fixes, or experiments without affecting the stable codebase. Each branch represents an independent line of work, enabling parallel development. This separation helps manage different project versions and ensures stability of the main project.
What is the primary purpose of using Git?