A student edits app.py, which Git already tracks, then runs `git commit -m "fix bug"` without running `git add`. What happens?
AThe edit to app.py is committed, because Git tracks the file
BNo commit is made, because no changes were staged
CGit deletes the edit, because it was not staged
DGit commits an empty file named app.py
git commit records the staging area (the index). With nothing staged, Git reports that no changes were added to the commit and makes no commit. The edit is still in the working folder. Running git add app.py first, or using git commit -a for tracked files, would include it.
Question 2 True / False
Git and GitHub are two names for the same software.
TTrue
FFalse
Answer: False
Git is a distributed version control system that works entirely on a local machine. GitHub is a web service for hosting Git repositories and adding features such as pull requests. Other hosts, such as GitLab and Bitbucket, also store Git repositories.
Question 3 Multiple Choice
When does Git report a merge conflict while merging branch feature into main?
AWhenever both branches contain new commits
BWhenever the two branches touched the same file in any way
CWhen both branches changed the same part of a file in different ways, so Git cannot choose automatically
DOnly when a file was deleted on one branch
Git can combine changes to different files, or to different parts of one file, automatically. A conflict arises when the same lines were changed differently on both sides (a delete-versus-edit clash also counts). Git then marks the region and waits for a person to decide.
Question 4 Short Answer
Why do developers usually create a new branch to build a feature instead of committing directly to the main branch?
Think about your answer, then reveal below.
Model answer: A branch isolates unfinished work. The main branch stays working and releasable while the feature is built and tested, other people can keep working in parallel, and the feature is merged in only when it is ready. If the idea fails, the branch can simply be abandoned.
Branches in Git are cheap pointers to commits, so creating one costs almost nothing. That makes isolating each piece of work practical.