Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is the git command to delete a remote branch named feature1?
Use git push origin --delete feature1 to delete the remote branch named feature1.
Click to reveal answer
beginner
Why can't you delete a remote branch using git branch -d?
git branch -d deletes only local branches. To delete remote branches, you must use git push origin --delete <branch-name>.
Click to reveal answer
intermediate
What happens if you try to delete a remote branch that does not exist?
Git will show an error message saying the branch was not found on the remote. No changes happen on the remote repository.
Click to reveal answer
intermediate
How can you verify that a remote branch was deleted successfully?
Run git fetch --prune to update your local list of remote branches, then use git branch -r to see remote branches. The deleted branch should no longer appear.
Click to reveal answer
advanced
What is the difference between git push origin --delete branch and git push origin :branch?
Both commands delete the remote branch named branch. The first is more explicit and easier to understand, while the second uses an older syntax by pushing an empty reference.
Click to reveal answer
Which command deletes a remote branch named bugfix?
Agit branch -d bugfix
Bgit delete branch bugfix
Cgit remote remove bugfix
Dgit push origin --delete bugfix
✗ Incorrect
git push origin --delete bugfix deletes the remote branch named bugfix. git branch -d deletes local branches only.
What does git fetch --prune do in relation to remote branches?
ADeletes local branches
BUpdates local remote branch list and removes deleted remote branches
CCreates new remote branches
DPushes local branches to remote
✗ Incorrect
git fetch --prune updates your local list of remote branches and removes references to remote branches that no longer exist.
If you want to delete a remote branch but keep your local copy, what should you do?
AUse <code>git push origin --delete branch</code> only
BUse <code>git branch -d branch</code>
CDelete local branch first
DUse <code>git remote prune origin</code>
✗ Incorrect
Deleting the remote branch with git push origin --delete branch does not affect your local branch.
What will happen if you run git push origin --delete nonexist when nonexist branch does not exist on remote?
AGit will show an error message
BNothing happens silently
CLocal branch will be deleted
DRemote branch will be created
✗ Incorrect
Git will show an error because the branch does not exist on the remote.
Which command is an older syntax to delete a remote branch named test?
Agit push origin --delete test
Bgit branch -d test
Cgit push origin :test
Dgit remote delete test
✗ Incorrect
git push origin :test deletes the remote branch test using older syntax by pushing an empty reference.
Explain how to delete a remote branch in git and verify it was deleted.
Think about the push command and how to update your local view of remote branches.
You got /3 concepts.
Describe the difference between deleting a local branch and a remote branch in git.
Consider where the branch lives and which commands affect which.
You got /3 concepts.
Practice
(1/5)
1. What does the command git push origin --delete feature1 do?
easy
A. Deletes the remote branch named 'feature1' from the origin repository.
B. Deletes the local branch named 'feature1'.
C. Deletes all branches except 'feature1' on the remote.
D. Renames the remote branch 'feature1' to 'origin'.
Solution
Step 1: Understand the command structure
The command uses git push with origin to interact with the remote repository named 'origin'.
Step 2: Interpret the --delete flag
The --delete flag tells Git to remove the specified branch from the remote repository.
Final Answer:
Deletes the remote branch named 'feature1' from the origin repository. -> Option A
Hint: Use 'git push origin --delete branch' to remove remote branches [OK]
Common Mistakes:
Confusing remote branch deletion with local branch deletion
Using 'git branch -d' which deletes local branches only
Thinking '--delete' renames branches
Assuming it deletes all branches
2. Which of the following is the recommended modern syntax to delete a remote branch named bugfix?
easy
A. git push origin :bugfix
B. git push origin --remove bugfix
C. git branch -r -d bugfix
D. git push origin --delete bugfix
Solution
Step 1: Review valid commands for deleting remote branches
The modern and clear syntax is git push origin --delete branch-name.
Step 2: Check each option
git push origin :bugfix uses an older syntax but is valid; however, the question asks for the recommended modern syntax, which is the explicit --delete flag. git push origin --remove bugfix uses a non-existent flag --remove. git branch -r -d bugfix deletes local remote-tracking branches, not remote branches.
Confusing remote branch deletion with local branch deletion
4. You ran git push origin --delete hotfix but got an error: error: unable to delete 'hotfix': remote ref does not exist. What is the most likely cause?
medium
A. The local branch 'hotfix' is checked out and cannot be deleted.
B. You do not have permission to delete branches on the remote.
C. The remote branch 'hotfix' does not exist on the remote repository.
D. The syntax of the command is incorrect.
Solution
Step 1: Analyze the error message
The error says 'remote ref does not exist', meaning the branch named 'hotfix' is not found on the remote.
Step 2: Check command and permissions
The command syntax is correct, and permission errors usually show different messages. The local branch state does not affect remote deletion.
Final Answer:
The remote branch 'hotfix' does not exist on the remote repository. -> Option C
Quick Check:
Remote branch missing causes 'remote ref does not exist' error [OK]
Hint: Check if remote branch exists before deleting [OK]
Common Mistakes:
Assuming local branch status affects remote deletion
Blaming permissions without checking branch existence
Mistaking syntax error for branch absence
Ignoring error message details
5. You want to delete multiple remote branches named feature1, feature2, and feature3 in one command using the --delete flag. Which of the following is the correct way to do this?
C. git push origin --delete feature1 feature2 feature3
D. git branch -r -d feature1 feature2 feature3
Solution
Step 1: Understand multi-branch deletion syntax
Git does not support deleting multiple remote branches in one command by listing them after --delete. You must run separate commands or use multiple --delete flags.
Step 2: Evaluate options
git push origin --delete feature1 feature2 feature3 is invalid syntax and will cause an error. git push origin --delete feature1 && git push origin --delete feature2 && git push origin --delete feature3 runs multiple commands separately, which works correctly. git push origin :feature1 :feature2 :feature3 uses old syntax without the --delete flag and may not be recommended. git branch -r -d feature1 feature2 feature3 deletes local remote-tracking branches, not remote branches.