Free Repository and Branch Management Questions and Answers — Questions and Answers
Question 1: What is a repository in GitHub used for?
- Hosting websites
- Running CI/CD pipelines
- Storing project files and version history (Correct answer)
- Encrypting user data
Correct answer: Storing project files and version history
A GitHub repository serves as a central location to store all project files, including code, documentation, and assets. Crucially, it also maintains the complete version history of these files, allowing users to track changes, revert to previous states, and collaborate effectively. It's the core unit for project management on GitHub.
Question 2: Which Git command creates a new branch?
- git init
- git checkout
- git create
- git branch (Correct answer)
Correct answer: git branch
The `git branch <branch-name>` command is used to create a new branch in your local repository. This command simply creates a new pointer to the current commit, allowing you to switch to this new branch and start making isolated changes. It's the first step in creating a separate line of development.
Question 3: Why are branches useful in Git?
- They increase merge conflicts
- They help avoid pull requests
- They isolate changes for safe development (Correct answer)
- They automatically deploy code
Correct answer: They isolate changes for safe development
Branches are invaluable in Git because they provide an isolated environment for developing new features or fixing bugs without impacting the main codebase. This isolation ensures that experimental or incomplete work doesn't break the stable version of the project. It promotes safe, organized development practices and allows for parallel workstreams.
Question 4: What does `git merge` do?
- Creates a new repository
- Deletes a branch
- Combines changes from one branch into another (Correct answer)
- Stages untracked files
Correct answer: Combines changes from one branch into another
The `git merge` command integrates changes from a specified branch into your current branch. It combines the commit histories of two branches, creating a new merge commit that incorporates all the changes from both lines of development. This is how features developed in isolation are brought back into the main project.
Question 5: How do you switch to another branch in Git?
- git update
- git switch
- git move
- git checkout (Correct answer)
Correct answer: git checkout
The `git checkout <branch-name>` command is used to switch between different branches in your repository. When you check out a branch, your working directory is updated to reflect the files and history of that specific branch. This allows you to work on different features or versions of your project independently.
Question 6: What is a remote repository?
- A backup copy
- A hidden folder
- A GitHub-hosted repository for collaboration (Correct answer)
- A template for creating branches
Correct answer: A GitHub-hosted repository for collaboration
A remote repository is a version of your project hosted on the internet or a network, typically on platforms like GitHub. It serves as a central point for multiple collaborators to push and pull changes, facilitating teamwork and providing a shared, up-to-date version of the project. This enables distributed development.
What is a repository in GitHub used for?