Git Git Remote Operations 2 β Questions and Answers
Question 1: What does `git clone --depth 1` do?
- Clones only the first commit
- Creates a shallow clone with only the most recent snapshot and no full history (Correct answer)
- Clones a single file
- Limits the clone to one branch
Correct answer: Creates a shallow clone with only the most recent snapshot and no full history
A shallow clone with `--depth 1` downloads only the latest snapshot of the repository without the full commit history, saving time and disk space.
Question 2: Which command updates the URL for an existing remote named `origin`?
- git remote update origin <new-url>
- git remote set-url origin <new-url> (Correct answer)
- git remote change 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 3: What does `git push --force-with-lease` do differently from `git push --force`?
- It pushes all branches simultaneously
- It only force-pushes if the remote branch has not been updated by someone else since your last fetch (Correct answer)
- It skips the pre-push hook
- It pushes only staged changes
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 4: Which command lists all configured remotes along with their URLs?
- git remote
- git remote show
- 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 5: 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 6: How do you fetch changes from all configured remotes at once?
- git fetch --all-remotes
- git fetch --all (Correct answer)
- git pull --all
- git remote fetch --all
Correct answer: git fetch --all
The `git fetch --all` command fetches from every remote listed in your configuration simultaneously.
What does `git clone --depth 1` do?