GitHub Foundations · 20% of the exam

Working with GitHub Repositories: free practice questions

5 sample questions from our 26-question bank for this domain — answers and explanations included. These are the same scenario-based style as the real GitHub exam.

1. A developer wants to undo the effects of a specific commit that was made several commits ago on a shared branch, without rewriting any existing commit history. Which Git approach is MOST appropriate?

  • A. git reset --hard <commit-sha> to move the branch pointer back
  • B. git revert <commit-sha> to create a new commit that reverses the changes✓ Correct
  • C. git commit --amend to edit the offending commit directly
  • D. git rebase -i to drop the offending commit from history
Explanation

'git revert <commit-sha>' creates a new commit that applies the inverse of the specified commit's changes, effectively undoing its effect while preserving the entire existing history — safe to use on shared branches. 'git reset --hard' moves the branch pointer to an earlier state, which rewrites history and would cause problems for other developers who have already based work on the removed commits. 'git commit --amend' can only modify the most recent commit, not an arbitrary earlier one. 'git rebase -i' (interactive rebase) also rewrites history by removing commits, which is dangerous on shared branches and would require force-pushing.

2. A team wants to standardize their development environments so that every contributor who opens the repository in GitHub Codespaces gets the same tools, extensions, and runtime versions pre-installed automatically. What should they add to the repository to achieve this?

  • A. A .github/workflows/codespaces.yml file that installs dependencies on each push
  • B. A devcontainer.json file (and optionally a Dockerfile) in the .devcontainer directory✓ Correct
  • C. A requirements.txt or package.json at the root of the repository
  • D. A CONTRIBUTING.md file that documents the required local setup steps
Explanation

A dev container configuration — typically a devcontainer.json file located in the .devcontainer directory — tells GitHub Codespaces (and other compatible tools) exactly what Docker image to use, which VS Code extensions to install, which ports to forward, and which setup commands to run when creating the environment. This ensures every developer gets an identical, reproducible environment automatically. Option A is incorrect because GitHub Actions workflows run in response to repository events (like pushes or pull requests) and are not used to configure the Codespaces environment itself. Option C is incorrect because dependency manifest files (requirements.txt, package.json) describe project dependencies but do not configure the OS-level environment, editor extensions, or runtime versions in Codespaces. Option D is incorrect because CONTRIBUTING.md is a documentation file for human readers; it has no effect on the automated provisioning of a Codespace.

3. A developer is working inside a GitHub Codespace and closes their browser tab without explicitly stopping or deleting the Codespace. What happens to the Codespace and its unsaved/uncommitted work?

  • A. The Codespace is immediately deleted and all uncommitted work is permanently lost
  • B. The Codespace is automatically committed and pushed to the repository's default branch
  • C. The Codespace transitions to a suspended state and persists, preserving uncommitted changes✓ Correct
  • D. The Codespace continues running indefinitely until the user manually stops it
Explanation

When a user closes a Codespace browser tab without stopping it, the Codespace enters a suspended (dormant) state after a short inactivity timeout. The container and its filesystem — including uncommitted changes — are preserved in that suspended state until the user resumes or the Codespace reaches the configured retention period and is deleted. It is NOT immediately deleted; work is preserved in the suspended state. GitHub never auto-commits or auto-pushes uncommitted changes on the user's behalf. The Codespace does not continue running indefinitely; it suspends after the inactivity timeout (default 30 minutes) to avoid unnecessary compute charges.

4. A developer accidentally included sensitive credentials in their last commit on a local branch that has NOT yet been pushed to GitHub. They want to fix the commit message AND remove the credentials from the commit entirely before pushing. Which Git command should they use?

  • A. git revert HEAD
  • B. git reset HEAD~1
  • C. git commit --amend✓ Correct
  • D. git cherry-pick HEAD
Explanation

git commit --amend allows the developer to modify the most recent (unpushed) commit — including its message and its staged content. By removing the credentials from the files, staging the corrected files with 'git add', and then running 'git commit --amend', the developer replaces the last commit with a new, corrected one. Option A (git revert HEAD) is incorrect because it creates a brand-new commit that undoes the previous one, which would still expose the credentials in the history. Option B (git reset HEAD~1) undoes the commit and unstages its changes but does not fix the commit — it leaves the developer with uncommitted changes that still need to be cleaned up; it also doesn't let them directly amend the message. Option D (git cherry-pick HEAD) is used to apply a commit from one branch onto another and is irrelevant here.

5. A repository maintainer navigates to the 'Insights' tab of their GitHub repository and selects 'Traffic'. Which TWO pieces of information can they find on this page? (Select TWO)

  • A. The number of repository clones over the past 14 days✓ Correct
  • B. The names and email addresses of all contributors
  • C. The number of unique visitors and page views over the past 14 days✓ Correct
  • D. A list of all open and closed pull requests
  • E. The top referring sites and popular content paths
Explanation

The Traffic insights page shows: (1) clone counts — how many times the repository has been cloned over the past 14 days — and (2) visitor/view counts — unique visitors and total page views over the same period. It also shows referring sites and popular content, but the question asks to select two. Contributor names and emails are found in the 'Contributors' insights page, not Traffic. Pull request lists are found in the Pull Requests tab, not Insights → Traffic.

21 more questions in this domain

Practice the full bank with instant grading, flashcards, and a timed mock exam.

Start practicing free
Working with GitHub Repositories — Free GitHub Foundations Practice Questions | DataCertPrep — Certification Prep