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 command do you use to push a new local branch to a remote repository?
Use git push -u origin <branch-name> to push a new local branch to the remote repository and set it to track the remote branch.
Click to reveal answer
beginner
What does the -u flag do when pushing a new branch?
The -u flag sets the upstream (tracking) reference, so future git push and git pull commands know which remote branch to interact with by default.
Click to reveal answer
intermediate
How can you check which remote branches your local branches are tracking?
Run git branch -vv to see local branches with their tracking remote branches and last commit info.
Click to reveal answer
beginner
If you create a new branch locally but forget to push it, what happens when you run git push?
Git will not push the new branch because it has no upstream set. You must push it explicitly with git push -u origin <branch-name> the first time.
Click to reveal answer
beginner
Why is it important to push new branches to the remote repository?
Pushing new branches shares your work with others and backs up your changes. It also allows collaboration and code review on that branch.
Click to reveal answer
Which command pushes a new branch named 'feature' to the remote and sets it to track?
Agit push feature
Bgit push origin
Cgit push -u origin feature
Dgit push -u feature origin
✗ Incorrect
The correct syntax is git push -u origin feature to push and set upstream tracking.
What does 'origin' usually refer to in git commands?
AThe default name for the remote repository
BThe local branch name
CThe commit hash
DThe current directory
✗ Incorrect
'origin' is the default name git gives to the remote repository you cloned from.
If you run git push without -u on a new branch, what happens?
APush fails because no upstream is set
BPush succeeds and sets upstream automatically
CPush deletes the branch
DPush merges branches
✗ Incorrect
Without upstream set, git does not know where to push the new branch, so push fails.
How do you see which remote branch your local branch is tracking?
Agit log
Bgit status
Cgit remote -v
Dgit branch -vv
✗ Incorrect
git branch -vv shows local branches with their tracking remote branches.
Why might you want to push a new branch to remote early?
ATo delete the branch
BTo share work and enable collaboration
CTo reset the repository
DTo change the commit history
✗ Incorrect
Pushing early shares your work and allows teammates to review or contribute.
Explain the steps and command to push a new local branch to a remote repository and set it to track the remote branch.
Think about how to share your new work with others using git.
You got /3 concepts.
Describe what happens if you try to push a new branch without setting upstream tracking and how to fix it.
Remember the role of the -u flag.
You got /3 concepts.
Practice
(1/5)
1. What is the correct command to push a new branch named feature1 to the remote repository?
easy
A. git push origin new feature1
B. git push origin feature1
C. git push new feature1
D. git push feature1 origin
Solution
Step 1: Understand the git push syntax
The correct syntax to push a branch is git push origin <branch-name>.
Step 2: Apply the branch name
Replace <branch-name> with feature1, resulting in git push origin feature1.
Final Answer:
git push origin feature1 -> Option B
Quick Check:
Push new branch = git push origin branch-name [OK]
Hint: Use 'git push origin branch-name' to push new branches [OK]
Common Mistakes:
Swapping origin and branch name order
Adding extra words like 'new'
Forgetting to specify the remote 'origin'
2. Which of the following commands correctly pushes a new branch dev to the remote named origin?
easy
A. git push origin/dev
B. git push origin:dev
C. git push dev origin
D. git push origin dev
Solution
Step 1: Recall the correct push syntax
The command to push a branch is git push origin <branch-name>.
Step 2: Match the branch and remote
Here, origin is the remote and dev is the branch, so git push origin dev is correct.
Final Answer:
git push origin dev -> Option D
Quick Check:
Push syntax = git push origin branch [OK]
Hint: Remember: remote first, then branch name [OK]
Common Mistakes:
Using colon instead of space between remote and branch
Swapping remote and branch order
Using slash notation incorrectly
3. Given the commands:
git checkout -b featureX
# make some changes
git add .
git commit -m "Add featureX"
git push origin featureX
What will be the result of the last command?
medium
A. The new branch featureX is created and pushed to the remote repository.
B. An error because the branch featureX does not exist locally.
C. Nothing happens because the branch is not checked out.
D. The changes are pushed but the branch is not created remotely.
Solution
Step 1: Analyze branch creation and commit
The command git checkout -b featureX creates and switches to the new branch featureX. Then changes are added and committed.
Step 2: Understand the push effect
git push origin featureX pushes the new branch featureX to the remote, creating it there.
Final Answer:
The new branch featureX is created and pushed to the remote repository. -> Option A
Quick Check:
Push new branch after commit = branch created remotely [OK]
Hint: Push after commit creates branch remotely [OK]
Common Mistakes:
Assuming branch must exist remotely before push
Forgetting to commit before pushing
Thinking push only updates existing branches
4. You run git push origin new-feature but get an error: error: src refspec new-feature does not match any. What is the most likely cause?
medium
A. You forgot to create or checkout the branch new-feature locally.
B. The remote repository origin does not exist.
C. You have uncommitted changes in your working directory.
D. You need to use git push -u origin new-feature instead.
Solution
Step 1: Understand the error message
The error means Git cannot find a local branch named new-feature to push.
Step 2: Identify the cause
This usually happens if the branch was never created or checked out locally before pushing.
Final Answer:
You forgot to create or checkout the branch new-feature locally. -> Option A
Quick Check:
Branch must exist locally before push [OK]
Hint: Create or checkout branch before pushing [OK]
Common Mistakes:
Assuming push creates branch locally
Ignoring error and retrying same command
Confusing remote existence with local branch
5. You have a local branch release with new commits. You want to push it to remote origin and set it to track the remote branch. Which command should you use?
hard
A. git push origin release
B. git push origin -u release
C. git push -u origin release
D. git push --set-upstream release origin
Solution
Step 1: Understand tracking branches
To set the local branch to track the remote branch, use the -u or --set-upstream option with git push.
Step 2: Apply correct syntax
The correct syntax is git push -u origin release which pushes and sets upstream tracking.
Final Answer:
git push -u origin release -> Option C
Quick Check:
Use -u to set upstream tracking [OK]
Hint: Use 'git push -u origin branch' to set tracking [OK]
Common Mistakes:
Placing -u after remote and branch incorrectly
Using --set-upstream with wrong argument order
Forgetting to set upstream and needing manual tracking