GitHub Foundations Certification (GH-900) — Questions and Answers
Question 1: What happens when you run `git pull --rebase` instead of `git pull`?
- Your local commits are squashed into one
- Your local commits are replayed on top of the fetched commits instead of creating a merge commit (Correct answer)
- All remote commits are discarded
- The pull is performed in dry-run mode
Correct answer: Your local commits are replayed on top of the fetched commits instead of creating a merge commit
The `--rebase` flag makes `git pull` reapply your local commits on top of the fetched upstream commits, producing a cleaner linear history.
Question 2: Which file can you set up to prevent specific file types from ever being committed to the local Git repository?
- git.ignore
- .gitignore (Correct answer)
- ignore.git
- gitignore.txt
Correct answer: .gitignore
Explanation: <br> Git is only for storing source code. Image files, compiled code, logs, and archives are examples of resources that should be kept out of the repository. Git will refuse to commit specific resources to the repository if a.gitignore file is configured, even if they are put to the staging area.
Question 3: When configuring SSH, which user should be created first?
- git (Correct answer)
- None of the above
- admin
- root
Correct answer: git
Explanation: <br> The user must first create the git repository before configuring the SSH. <br> <br> Linus Torvalds designed Git, an open-source version management system, in 2005. <br> <br> Git is a distributed version control system, which implies that every developer's computer has access to the whole codebase and history, allowing for easy branching and merging.
Question 4: How do you push a local branch `feature` to the remote `origin` and set it as the upstream?
- git push origin --track feature
- git push -u origin feature (Correct answer)
- git push origin feature
- git push --set-upstream feature origin
Correct answer: git push -u origin feature
The `-u` (or `--set-upstream`) flag sets the remote branch as the upstream for the local branch, enabling future `git push` without arguments.
Question 5: What do refs stores entail?
- None of the above
- SHA-1 value (Correct answer)
- Project name
- Branch name
Correct answer: SHA-1 value
Explanation: <br> The Resilient File System (ReFS) is Microsoft's newest file system, designed to increase data availability, scale quickly to huge data sets across a variety of workloads, and guarantee data integrity and corruption resistance. It aims to meet a growing number of storage scenarios while also laying the groundwork for future improvements.
Question 6: The git command ________is used to add tags to a commit.
- gitcheckout [branch name]
- git tag [commitID] (Correct answer)
- git show [commit]
- git rm [file]
Correct answer: git tag [commitID]
Explanation: <br> The primary driver of tag generation, modification, and deletion is the git tag command. Annotated tags and lightweight tags are the two sorts of tags.
Question 7: Which command lists all configured remotes along with their URLs?
- git remote show
- git remote
- git remote -v (Correct answer)
- git remote list
Correct answer: git remote -v
The `git remote -v` command displays all remote names along with their fetch and push URLs.
Question 8: How do you stage the deletion of a tracked file and prepare it for the next commit?
- git delete <file>
- git stage --delete <file>
- git rm <file> (Correct answer)
- git add <file>
Correct answer: git rm <file>
The `git rm <file>` command removes the file from the working directory and stages the deletion so it will be recorded in the next commit.
Question 9: How do you display the number of insertions and deletions per file in each commit?
- git log --stat (Correct answer)
- git log --diff-stat
- git log --files
- git log --changes
Correct answer: git log --stat
The `--stat` option adds a summary of file changes (insertions/deletions) below each commit entry in the log.
Question 10: What is the purpose of a global `.gitignore` file configured with `core.excludesfile`?
- Prevents pushes of ignored files
- Overrides local `.gitignore` rules
- Applies ignore rules to all repositories for the current user without modifying each repo's `.gitignore` (Correct answer)
- Ignores files in the system Git installation
Correct answer: Applies ignore rules to all repositories for the current user without modifying each repo's `.gitignore`
The `core.excludesfile` setting points to a global ignore file that applies to every repository cloned by the user, useful for IDE files and OS-specific artifacts.
Question 11: Which command shows the difference between the working directory and the staging area?
- git status -v
- git diff HEAD
- git diff (Correct answer)
- git diff --staged
Correct answer: git diff
A plain `git diff` shows the difference between the working directory and what is currently staged (the index).
Question 12: How do you create a commit with a message provided inline?
- git commit -t 'message'
- git commit --note 'message'
- git commit -m 'message' (Correct answer)
- git commit --msg 'message'
Correct answer: git commit -m 'message'
The `-m` flag allows you to pass the commit message directly on the command line without opening an editor.
Question 13: Where does Git look for configuration in order of precedence from highest to lowest?
- Local → Global → System (Correct answer)
- System → Global → Local
- Global → System → Local
- Local → System → Global
Correct answer: Local → Global → System
Git applies configuration in order: local (`.git/config`) overrides global (`~/.gitconfig`) which overrides system (`/etc/gitconfig`).
Question 14: What is a merge conflict?
- When the network fails during a push
- When a branch is deleted during a merge
- When a commit message is missing
- When two branches have changes to the same lines of a file that Git cannot automatically reconcile (Correct answer)
Correct answer: When two branches have changes to the same lines of a file that Git cannot automatically reconcile
A merge conflict occurs when two branches modify the same lines of a file and Git cannot determine which change to keep.
Question 15: What does `git stash pop` do compared to `git stash apply`?
- pop applies only the latest stash; apply applies all stashes
- They are identical
- pop discards the stash without applying; apply applies it
- pop applies the stash and removes it from the stash list; apply applies it but keeps it (Correct answer)
Correct answer: pop applies the stash and removes it from the stash list; apply applies it but keeps it
The `git stash pop` command applies the most recent stash entry and then drops it from the stash list, while `git stash apply` applies it without removing it.
Question 16: What is a Git tag, and how does a lightweight tag differ from an annotated tag?
- Tags are branches that do not move; there is no difference between types
- Tags mark important commits; lightweight is just a pointer while annotated stores extra metadata like tagger and message (Correct answer)
- Lightweight tags are for local use only; annotated tags are for remotes
- Lightweight tags expire; annotated tags are permanent
Correct answer: Tags mark important commits; lightweight is just a pointer while annotated stores extra metadata like tagger and message
A lightweight tag is merely a named reference to a commit, while an annotated tag is a full Git object containing the tagger's name, email, date, and a message.
Question 17: Which `git merge` option always creates a merge commit even if fast-forward is possible?
- --rebase
- --force
- --squash
- --no-ff (Correct answer)
Correct answer: --no-ff
The `--no-ff` flag forces Git to create a merge commit regardless of whether a fast-forward is possible.
Question 18: What is the purpose of `git merge --squash`?
- Deletes all commits on the branch
- Forces a fast-forward merge
- Merges only the last commit
- Combines all commits from a branch into one staged change without committing (Correct answer)
Correct answer: Combines all commits from a branch into one staged change without committing
The `--squash` option collapses all commits from the source branch into a single staged change that you then commit manually.
Question 19: With a Windows-based Git install, what is the default text editor for the Bash shell?
- Notepad++
- Emacs
- Vim (Correct answer)
- Bash
Correct answer: Vim
Explanation: <br> When Git Bash is installed on a Windows PC, Vim is the default text editor. Unfortunately, for Windows users who are new with Vim, the tool tends to provide an unnecessary stumbling block in the way of Git beginners. Do you want to make it easier for Windows users to understand Git? Replace Git's default text editor with something more user-friendly, such as Emacs or Notepad++.
Question 20: How do you modify the message of the most recent commit without creating a new commit?
- git revert HEAD --message "new message"
- git commit --amend -m "new message" (Correct answer)
- git log --amend
- git reset --soft HEAD~1 followed by git commit
Correct answer: git commit --amend -m "new message"
`git commit --amend` replaces the most recent commit with a new one, allowing you to update the message or add more changes to it.
Question 21: Which two configuration parameters does Git want to be configured after you install it and before you make your first commit?
- username and password
- username and email address (Correct answer)
- email address and password
- username and IP address
Correct answer: username and email address
Explanation: <br> Every commit should have a username and an email address linked with it, according to Git. In a distributed context, this allows all source code contributors to quickly identify and communicate with co-contributors. <br> <br> The git config command can be used to set up the user.name and user.email attributes, as seen below: <br> <br> /c/ git quiz (tutorial) <br> $ git config --local user.name "Git quiz taker" <br> /c/ git quiz (tutorial) <br> $ git config --local user.email "me@example.com" <br> <br> If the user.name and user.email address properties are not explicitly provided, Git will supply the appropriate information to a commit using the local machine's IP address and the OS' logon credentials. It will also provide a rather detailed warning message about properly specifying these properties.
Question 22: What does `git sparse-checkout` enable?
- Limiting the number of commits fetched
- Checking out a repository without the commit history
- Checking out only a subset of the repository's files or directories (Correct answer)
- Checking out branches without remote-tracking refs
Correct answer: Checking out only a subset of the repository's files or directories
Git sparse-checkout allows you to check out only specific files or directories from a large repository, reducing disk usage and improving performance.
Question 23: What does `git reset --soft HEAD~1` do?
- Reverts the last commit by creating a new revert commit
- Moves HEAD back one commit and unstages all changes
- Deletes the last commit and discards all changes
- Moves HEAD back one commit but keeps changes staged (Correct answer)
Correct answer: Moves HEAD back one commit but keeps changes staged
`--soft` moves the HEAD pointer back one commit but leaves all changes intact in the staging area (index).
Question 24: Which setting controls line-ending conversion when checking out and committing files on Windows?
- core.autocrlf (Correct answer)
- core.newline
- core.lineending
- core.eol
Correct answer: core.autocrlf
The `core.autocrlf` setting controls whether Git automatically converts CRLF line endings on Windows to LF on commit and vice versa on checkout.
Question 25: Who is credited with the invention of Git?
- James Gosling
- Kohsuke Kawaguchi
- Linus Torvalds (Correct answer)
- Kohsuke Kawaguchi
Correct answer: Linus Torvalds
Explanation: <br> Linus Torvalds forged ahead with the development of his own open source distributed version control system after a series of disagreements and disappointment within the Linux community over the source code management tool BitKeeper. As a result, Torvalds is credited with the development of Git.
Question 26: Which command discards unstaged changes to a tracked file?
- Both B and C are correct (Correct answer)
- git restore <file>
- git reset <file>
- git checkout -- <file>
Correct answer: Both B and C are correct
Both `git restore <file>` (modern syntax) and `git checkout -- <file>` (older syntax) discard working directory changes to a tracked file.
Question 27: Which Git command undoes a commit by creating a new commit that reverses the changes?
- git reset
- git revert (Correct answer)
- git checkout
- git restore
Correct answer: git revert
git revert creates a new commit that reverses a previous commit's changes, keeping the original commit in history.
Question 28: How long does Git keep reflog entries accessible by default before they expire?
- 60 days
- 90 days (Correct answer)
- 7 days
- 30 days
Correct answer: 90 days
By default, Git keeps reflog entries for 90 days, configurable via `gc.reflogExpire` in your Git config.
Question 29: How do you unstage a file that was added with `git add`?
- git reset HEAD <file>
- git unstage <file>
- git restore --staged <file> (Correct answer)
- git remove <file>
Correct answer: git restore --staged <file>
The `git restore --staged <file>` command removes the file from the staging area without discarding the working directory changes.
Question 30: Which command shows commits that exist in `feature` but not in `main`?
- git diff main feature
- git log main..feature (Correct answer)
- git log feature..main
- git log main...feature
Correct answer: git log main..feature
The `main..feature` syntax (double dot) shows commits reachable from `feature` that are not reachable from `main`.
Question 31: What is a remote-tracking branch?
- A branch that automatically pushes on every commit
- A backup of the local main branch
- A branch on the remote server
- A local read-only reference that mirrors the state of a remote branch as of the last fetch (Correct answer)
Correct answer: A local read-only reference that mirrors the state of a remote branch as of the last fetch
Remote-tracking branches (e.g., `origin/main`) are local references that represent the last known state of branches on the remote.
Question 32: What is the safest preparation before performing a potentially destructive operation like `git reset --hard`?
- Run git fetch to synchronize with the remote first
- Delete all untracked files with git clean to reduce confusion
- Stash all changes before running the reset
- Create a backup branch to preserve your current state (Correct answer)
Correct answer: Create a backup branch to preserve your current state
Creating a backup branch with `git branch backup` preserves your current commit and can be restored instantly if the operation goes wrong.
Question 33: Which of the following does not fall inside the scope of Git configuration?
- Global
- Local
- System
- User (Correct answer)
Correct answer: User
Explanation: <br> Each Git repository's.git folder contains the configuration file for the local scope. <br> <br> The system scope configuration file is kept in a subdirectory of the Git installation. <br> <br> The global scope's configuration file is located in the user's home directory, which is why newcomers to Git often confuse global scope with user scope, as globally scoped variables are set uniquely for each user logging into the local OS. However, global, not user, is the correct name for this level of scope.
Question 34: Which option in `git log` excludes merge commits from the output?
- --exclude-merges
- --skip-merges
- --no-merges (Correct answer)
- --without-merges
Correct answer: --no-merges
The `--no-merges` flag filters out any commit that has more than one parent, effectively hiding merge commits.
Question 35: Which command searches the commit log for commits whose message contains a specific string?
- git log --grep='string' (Correct answer)
- git log --match='string'
- git log --find='string'
- git log --search='string'
Correct answer: git log --grep='string'
The `--grep` flag filters the commit log to show only commits whose message matches the given pattern.
Question 36: What is the purpose of the `ORIG_HEAD` reference in Git?
- The original first commit in the repository
- A reference saved to the previous HEAD before a dangerous operation like merge or rebase (Correct answer)
- A backup of the stash
- The head of the original remote branch
Correct answer: A reference saved to the previous HEAD before a dangerous operation like merge or rebase
Git automatically saves the current HEAD to `ORIG_HEAD` before performing merges, rebases, or resets, providing an easy undo target.
Question 37: Which command sets your global Git username?
- git init --user 'Name'
- git config --global user.name 'Name' (Correct answer)
- git config user.name 'Name'
- git setup --name 'Name'
Correct answer: git config --global user.name 'Name'
The `git config --global user.name 'Name'` command sets the author name for all commits across all repositories on the system.
Question 38: Which Git command shows the patch that corresponds to each commit?
- git remote -v
- git log
- git log-p (Correct answer)
- git branch
Correct answer: git log-p
Explanation: <br> The git log -p command shows the patch for each commit.
Question 39: What is the purpose of `git gc` (garbage collection)?
- Deletes all remote-tracking branches
- Removes all untracked files from the working directory
- Cleans up unnecessary objects and optimizes the local repository's pack files (Correct answer)
- Removes all stashes
Correct answer: Cleans up unnecessary objects and optimizes the local repository's pack files
The `git gc` command removes loose objects that are no longer reachable, packs existing loose objects, and prunes expired reflog entries to optimize the repository.
Question 40: How do you clone only a specific branch from a remote repository?
- git clone --only <branch-name> <url>
- git clone -b <branch-name> <url>
- git clone --branch <branch-name> <url>
- Both A and B are correct (Correct answer)
Correct answer: Both A and B are correct
Both `--branch` and its shorthand `-b` instruct `git clone` to check out the specified branch after cloning.
Question 41: How do you configure Git to always rebase instead of merge when running `git pull`?
- git config --global pull.strategy rebase
- git config --global merge.default rebase
- git config --global pull.rebase true (Correct answer)
- git config --global rebase.onpull true
Correct answer: git config --global pull.rebase true
Setting `pull.rebase true` in the global Git configuration makes every `git pull` operation use rebase by default.
Question 42: What does the three-dot syntax `git log main...feature` show?
- Commits in both branches
- Commits only in main
- All commits since the repository was created
- Commits reachable from either branch but not their common ancestor (Correct answer)
Correct answer: Commits reachable from either branch but not their common ancestor
The triple-dot syntax shows commits that are reachable from either `main` or `feature` but not from their common merge base.
Question 43: Which command removes untracked files from the working directory?
- git clean -f (Correct answer)
- git restore .
- git reset --hard
- git rm -r .
Correct answer: git clean -f
`git clean -f` removes untracked files from the working directory; the `-f` (force) flag is required by default as a safety measure.
Question 44: What is the effect of `git commit -a`?
- Commits with an empty message
- Commits all files in the repository including untracked ones
- Amends the previous commit
- Automatically stages all tracked modified files and commits them (Correct answer)
Correct answer: Automatically stages all tracked modified files and commits them
The `-a` flag automatically stages all modifications and deletions to tracked files before committing, skipping the need for explicit `git add`.
Question 45: Which command removes a remote called `upstream` from your configuration?
- git remote delete upstream
- git remote -d upstream
- git remove remote upstream
- git remote remove upstream (Correct answer)
Correct answer: git remote remove upstream
The `git remote remove upstream` command removes the remote named `upstream` and all associated remote-tracking branches.
Question 46: What does `git log -p` display?
- A graph of branch history
- Only commit authors
- Each commit along with the diff it introduced (Correct answer)
- Commits sorted by patch size
Correct answer: Each commit along with the diff it introduced
The `-p` (or `--patch`) flag shows each commit entry together with the full diff of changes introduced by that commit.
Question 47: For dealing with Git, which of the following command line environments is used?
- Git Boot
- Git lab
- Git Bash (Correct answer)
- GitHub
Correct answer: Git Bash
Explanation: <br> For working with Git, the Git Bash command line environment is utilized.
Question 48: What does the `git shortlog` command produce?
- A summary of commits grouped by author (Correct answer)
- A log with abbreviated hashes
- The last 5 commits only
- A log without merge commits
Correct answer: A summary of commits grouped by author
The `git shortlog` command groups commits by author and shows the count and subject lines for each author's commits.
Question 49: What exactly is Gitosis?
- PHP program
- None of the above
- set of scripts (Correct answer)
- Java program
Correct answer: set of scripts
Explanation: <br> Gitosis is a tool that manages and controls access to hosted Git repositories from afar. It enables fine-grained control of read and write access over SSH without the need for users to have local system accounts on the server.
Question 50: How do you configure Git to use a proxy for HTTPS connections?
- git config --global http.proxy http://proxy:port (Correct answer)
- git config --global remote.proxy http://proxy:port
- git config --global proxy.url http://proxy:port
- git config --global network.proxy http://proxy:port
Correct answer: git config --global http.proxy http://proxy:port
Setting `http.proxy` in the global Git configuration routes all HTTPS Git operations through the specified proxy server.
Question 51: What is Git's `refspec` used for?
- A specification for the commit message format
- A pattern that maps remote references to local references during fetch and push (Correct answer)
- A list of branches to ignore during push
- A reference to a specific file in the repository
Correct answer: A pattern that maps remote references to local references during fetch and push
A refspec is a mapping in the format `<src>:<dst>` that tells Git how to map remote branch references to local ones during fetch or push operations.
Question 52: What does `git config --global push.default current` do?
- Sets origin as the default remote
- Pushes the current branch to a remote branch of the same name (Correct answer)
- Prevents pushes to the main branch
- Pushes all branches by default
Correct answer: Pushes the current branch to a remote branch of the same name
Setting `push.default` to `current` makes `git push` target a remote branch with the same name as the local branch being pushed.
Question 53: What does interactive rebase (`git rebase -i`) allow you to do?
- Merge branches interactively
- Choose which files to rebase
- Rebase while resolving conflicts interactively
- Reorder, squash, edit, or drop commits before replaying them (Correct answer)
Correct answer: Reorder, squash, edit, or drop commits before replaying them
Interactive rebase opens an editor listing the commits to be replayed, letting you reorder, squash, split, edit, or drop individual commits.
Question 54: What is the key difference between `git reset --mixed` and `git reset --soft`?
- There is no functional difference between the two modes
- --mixed deletes working directory changes while --soft keeps them staged
- --mixed preserves staged changes while --soft discards them
- --mixed unstages changes but keeps them in the working directory while --soft keeps them staged (Correct answer)
Correct answer: --mixed unstages changes but keeps them in the working directory while --soft keeps them staged
`--mixed` (the default) moves HEAD and unstages changes, placing them back in the working directory, while `--soft` moves HEAD and keeps everything staged.
Question 55: What information is stored in a Git commit object?
- The branch name it was created on
- Only the diff of changes
- The remote URL it was pushed to
- A tree snapshot, author, committer, message, and parent reference(s) (Correct answer)
Correct answer: A tree snapshot, author, committer, message, and parent reference(s)
A Git commit object stores a pointer to the tree (snapshot), author and committer info with timestamps, the commit message, and references to parent commits.
Question 56: Which command finds the most recent tag reachable from a commit?
- git log --tags
- git describe (Correct answer)
- git tag --recent
- git tag --nearest
Correct answer: git describe
The `git describe` command finds the most recent tag reachable from the current commit and outputs it along with the number of additional commits and the abbreviated hash.
Question 57: What does `git log --follow <file>` do compared to `git log <file>`?
- Tracks the file's history across renames (Correct answer)
- Limits history to the last rename
- Follows symlinks to the real file
- Shows only commits where the file was created
Correct answer: Tracks the file's history across renames
The `--follow` flag instructs Git to continue the log history across file renames, showing the full lineage of a file.
Question 58: Why is `git revert` preferred over `git reset` when undoing changes on a shared branch?
- git reset only works on branches that have no remote tracking branch
- git revert automatically notifies all collaborators of the undone change
- git revert is significantly faster to execute than git reset
- git revert preserves history while git reset rewrites it, which disrupts collaborators (Correct answer)
Correct answer: git revert preserves history while git reset rewrites it, which disrupts collaborators
git revert adds a new commit to undo changes, preserving history, while git reset rewrites history and would force collaborators to re-sync, causing conflicts.
Question 59: Which command shows a compact one-line summary of each commit in the log?
- git log --short
- git log --oneline (Correct answer)
- git log --summary
- git log --brief
Correct answer: git log --oneline
The `git log --oneline` flag formats each commit as a single line showing the abbreviated hash and subject message.
Question 60: Which command stages only specific hunks of a modified file interactively?
- git stage --hunks <file>
- git add -p <file> (Correct answer)
- git add -i <file>
- git add --selective <file>
Correct answer: git add -p <file>
The `git add -p` (patch) command interactively presents each change hunk and lets you choose whether to stage it.
Question 61: What does `git commit --allow-empty` do?
- Creates a commit even when there are no staged changes (Correct answer)
- Commits only whitespace changes
- Removes all files and commits that state
- Commits without staging any files
Correct answer: Creates a commit even when there are no staged changes
The `--allow-empty` flag creates a commit with no changes to the tree, which is useful for triggering CI pipelines or marking milestones.
Question 62: What does `git archive` do?
- Archives old commits to save disk space
- Exports a snapshot of the repository tree as a tar or zip archive without Git metadata (Correct answer)
- Compresses the `.git` directory
- Creates a backup of all branches
Correct answer: Exports a snapshot of the repository tree as a tar or zip archive without Git metadata
The `git archive` command creates a compressed archive of the files in a tree object (commit, tag, or branch), excluding the `.git` directory.
Question 63: What does `git bisect` help you do?
- Binary search through commit history to find the commit that introduced a bug (Correct answer)
- Compare two branches side by side
- Split a commit into two smaller commits
- Split a repository into two separate repositories
Correct answer: Binary search through commit history to find the commit that introduced a bug
The `git bisect` command automates a binary search through commit history, allowing you to efficiently pinpoint which commit introduced a regression.
Question 64: Which tool is the current recommended way to permanently remove a sensitive file from an entire Git repository's history?
- git rm --purge <file>
- git reset --history-rewrite <file>
- git filter-repo (Correct answer)
- git revert --all-commits <file>
Correct answer: git filter-repo
`git filter-repo` is the officially recommended tool for rewriting history to remove files; it replaces the older and slower `git filter-branch`.
Question 65: Which merge strategy is default when merging two branches?
- octopus
- ours
- resolve
- recursive (Correct answer)
Correct answer: recursive
The 'recursive' strategy is the default for two-branch merges; newer Git versions use 'ort' which is an improved version of recursive.
Question 66: How do you create a stash that includes untracked files?
- git stash --include-untracked
- git stash -a
- git stash -u
- Both B and C are correct (Correct answer)
Correct answer: Both B and C are correct
Both `git stash -u` and `git stash --include-untracked` stash untracked files in addition to tracked modified files.
Question 67: All objects and references from a specified repository are downloaded using this command.
- git fetch (Correct answer)
- git help
- git log -n
- git config -list
Correct answer: git fetch
Explanation: <br> The git fetch command downloads all of the objects and references in a given repository.
Question 68: Which flag with `git revert` prevents it from automatically creating a commit, letting you stage multiple reverts as a single commit?
- --no-commit (Correct answer)
- --hold
- --soft
- --staged
Correct answer: --no-commit
`git revert --no-commit` (or `-n`) applies the revert changes to the working tree and index without committing, so you can batch multiple reverts into one commit.
Question 69: Which command updates the URL for an existing remote named `origin`?
- git remote set-url origin <new-url> (Correct answer)
- git remote change origin <new-url>
- git remote update origin <new-url>
- git config remote.origin.url <new-url>
Correct answer: git remote set-url origin <new-url>
The `git remote set-url origin <new-url>` command changes the URL associated with the `origin` remote.
Question 70: What protocol does Git use when a remote URL starts with `git@github.com:`?
- FTP
- SSH (Correct answer)
- HTTPS
- HTTP
Correct answer: SSH
URLs in the form `git@github.com:` use SSH as the transport protocol, requiring an SSH key pair for authentication.
Question 71: Which command switches to an existing branch using the modern Git syntax?
- git move branch-name
- git use branch-name
- git switch branch-name (Correct answer)
- git checkout branch-name
Correct answer: git switch branch-name
The `git switch` command (introduced in Git 2.23) is the modern way to switch between existing branches.
Question 72: What does `git reset HEAD~1 --soft` do?
- Moves changes to the working directory
- Resets the index and working directory to HEAD~1
- Undoes the last commit but keeps its changes staged (Correct answer)
- Deletes the last commit and its changes entirely
Correct answer: Undoes the last commit but keeps its changes staged
A soft reset moves the branch pointer back one commit while leaving all the changes from that commit in the staging area ready to be recommitted.
Question 73: Which command displays all active Git configuration values and their sources?
- git config --all
- git config -v
- git config --dump
- git config --list --show-origin (Correct answer)
Correct answer: git config --list --show-origin
The `git config --list --show-origin` command lists every configuration setting currently in effect along with the file path where each setting comes from.
Question 74: What is the 'detached HEAD' state?
- When remote and local branches are out of sync
- When a branch has no commits
- A corrupted repository state
- When HEAD points directly to a commit rather than a branch reference (Correct answer)
Correct answer: When HEAD points directly to a commit rather than a branch reference
Detached HEAD occurs when HEAD points to a specific commit rather than a named branch, usually after checking out a commit directly.
Question 75: What is the main advantage of `git rebase` over `git merge` for integrating changes?
- Rebase works on remote branches while merge does not
- Rebase is faster for large repositories
- Rebase preserves the exact original commit timestamps
- Rebase produces a cleaner, linear commit history without merge commits (Correct answer)
Correct answer: Rebase produces a cleaner, linear commit history without merge commits
Rebasing replays commits on top of another branch, resulting in a linear history free of merge commits, which is easier to read and bisect.
Question 76: What does `git clean -fd` do?
- Force-deletes the last commit from history
- Removes staged files and empty directories
- Cleans the reflog and triggers garbage collection
- Removes untracked files and untracked directories (Correct answer)
Correct answer: Removes untracked files and untracked directories
`git clean -fd` removes untracked files (`-f` for force) and untracked directories (`-d`), leaving only tracked content in the working directory.
Question 77: What does `git reset --hard HEAD~1` do?
- Moves HEAD back one commit and permanently discards all changes (Correct answer)
- Moves HEAD back one commit and keeps changes in the working directory
- Creates a new revert commit that undoes the last commit
- Moves HEAD back one commit and keeps changes staged
Correct answer: Moves HEAD back one commit and permanently discards all changes
`--hard` moves HEAD back and discards both staged and working directory changes, making the operation irreversible without reflog.
Question 78: What does `git push --force-with-lease` do differently from `git push --force`?
- It pushes only staged changes
- It skips the pre-push hook
- It only force-pushes if the remote branch has not been updated by someone else since your last fetch (Correct answer)
- It pushes all branches simultaneously
Correct answer: It only force-pushes if the remote branch has not been updated by someone else since your last fetch
The `--force-with-lease` flag verifies that no one else has pushed new commits since your last fetch before overwriting the remote branch.
Question 79: Which strategy does `git merge -s octopus` use?
- Merges two branches with conflict resolution
- Merges more than two branches simultaneously (Correct answer)
- Resets both branches to a common ancestor
- Creates an empty merge commit
Correct answer: Merges more than two branches simultaneously
The octopus merge strategy is designed to merge more than two branches at once, ideal for integrating multiple feature branches simultaneously.
Question 80: What is a `.gitignore` file used for?
- Storing commit message templates
- Specifying file patterns that Git should not track or commit (Correct answer)
- Configuring remote repositories
- Listing files that Git will automatically commit
Correct answer: Specifying file patterns that Git should not track or commit
A `.gitignore` file contains patterns of file names and directories that Git should ignore when determining untracked files.
Question 81: Which format option for `git log --pretty` displays the full commit hash, author, date, and full message?
- --pretty=full (Correct answer)
- --pretty=short
- --pretty=medium
- --pretty=fuller
Correct answer: --pretty=full
The `--pretty=full` format shows the commit hash, author, committer, and full commit message body.
Question 82: Which command applies a specific commit from another branch onto the current branch?
- git merge <commit-hash>
- git patch <commit-hash>
- git apply <commit-hash>
- git cherry-pick <commit-hash> (Correct answer)
Correct answer: git cherry-pick <commit-hash>
The `git cherry-pick <commit-hash>` command applies the changes introduced by the specified commit onto the current branch as a new commit.
Question 83: In June 2018, which company paid $7.5 billion for GitHub?
- Oracle
- Microsoft (Correct answer)
- IBM
Correct answer: Microsoft
Explanation: <br> Given Git's Linux and Apache history, many people were startled when Microsoft announced their takeover of GitHub, a move that resulted in numerous projects inexplicably migrating to GitHub competitor GitLab. On GitHub, expect to see more Zune and Windows CE projects.
Question 84: How does `git revert` differ from `git reset` when undoing changes?
- They are identical in behavior
- reset creates a new commit; revert moves the branch pointer
- revert only works on files; reset works on commits
- revert creates a new commit that undoes changes; reset moves the branch pointer back (Correct answer)
Correct answer: revert creates a new commit that undoes changes; reset moves the branch pointer back
The `git revert` command creates a new commit that undoes the changes of a previous commit, preserving history, while `git reset` moves the branch pointer and can rewrite history.
Question 85: Which `git reset` mode is used by default when no flag is specified?
- --soft
- --merge
- --mixed (Correct answer)
- --hard
Correct answer: --mixed
`git reset` defaults to `--mixed`, which moves HEAD back and unstages changes while keeping them in the working directory.
Question 86: Which command allows you to find and recover the hash of a commit lost after `git reset --hard`?
- git reflog (Correct answer)
- git stash list
- git log --all --oneline
- git fsck --lost-found
Correct answer: git reflog
`git reflog` records a history of all HEAD movements including resets, letting you find the lost commit hash and restore it with `git reset --hard <hash>`.
Question 87: What command aborts an in-progress merge and returns to the pre-merge state?
- git merge --undo
- git checkout --no-merge
- git reset --merge
- git merge --abort (Correct answer)
Correct answer: git merge --abort
The `git merge --abort` command stops the merge in progress and restores the working directory to the state before the merge began.
Question 88: Which command adds a new remote repository with the alias `origin`?
- git remote origin add <url>
- git add remote origin <url>
- git set remote origin <url>
- git remote add origin <url> (Correct answer)
Correct answer: git remote add origin <url>
The `git remote add origin <url>` command registers a new remote repository under the alias `origin`.
Question 89: What is the effect of merging a branch into itself?
- A new empty commit is created
- Nothing happens — it is a no-op
- The branch is duplicated
- Git throws an error (Correct answer)
Correct answer: Git throws an error
Git prevents merging a branch into itself and throws an error stating there is nothing to merge.
Question 90: What is a signed commit in Git?
- A commit with a very long message
- A commit that requires two approvals
- A commit cryptographically signed with a GPG key to verify authorship (Correct answer)
- A commit tagged with a version number
Correct answer: A commit cryptographically signed with a GPG key to verify authorship
A signed commit includes a GPG signature attached by the author, allowing others to verify the commit's authenticity and integrity.
GitHub Foundations Certification (GH-900)
The GitHub Foundations certification validates core knowledge of Git version control and GitHub platform features, including repositories, commits, branching, remote operations, collaboration tools, and project management.
Exam Rules
- You can skip questions and return to them later
- Flag questions for review before submitting
- No feedback shown until you submit the entire exam
- Unanswered questions count as wrong — answer everything
- 10 pretest questions are mixed in and don't affect your score
- Timer auto-submits when time runs out
- Your progress is auto-saved every 30 seconds