GitLab Git Associate study materials
GitLab Git Associate study resources

GitLab Git Associate: Git fundamentals

GitLab Git Associate · Work through your exam, one topic at a time.

All guide sections

Git fundamentals

This domain tests whether you understand Git's object model and the commands that move changes between the working tree, the index, and the commit graph. Expect questions on what a commit records, how branches relate to commits, and when a merge creates a merge commit.

The three areas and the object model

  • The working tree holds editable files; the index (staging area) holds the snapshot the next commit will record; the repository (.git) holds immutable objects.
  • A commit points to a tree (a directory snapshot), zero or more parent commits, and metadata such as author, committer, and message. It does not store a diff, although tools display diffs between commits.
  • A branch is a movable pointer to a commit. HEAD normally points to the current branch; checking out a commit directly produces a detached HEAD.
  • git add snapshots file content into the index at that moment. Editing the file afterwards leaves the newer content unstaged.

Merging

A fast-forward happens when the target branch has not diverged: Git moves the pointer forward and creates no merge commit. A three-way merge happens when both branches advanced: Git uses the merge base to combine changes and creates a commit with two parents. Conflicts leave markers and unmerged index entries until you edit, git add, and git commit.

Worked example

main is at C2. You create feature, then add C3 and C4. Meanwhile main gains C5. git switch main && git merge feature cannot fast-forward because main is not an ancestor of feature; Git finds merge base C2, combines C3-C4 with C5, and creates merge commit M with parents C4 and C5. If main had stayed at C2, the same merge would fast-forward to C4 and create no M.

Traps that cost marks

  • Saying a commit stores only changed lines; it stores a full tree snapshot linked to parent commits.
  • Believing a branch is a folder copy; it is a pointer named by a commit ID.
  • Forgetting that git commit -a skips untracked files.
  • Assuming every merge creates a merge commit.