CodeBlanks Logo Icon CodeBlanks

Upstream tracking

Learn to set an upstream branch for easy pushing.

What Is Upstream?

Upstream refers to the remote branch tracked by a local branch. For example, you can configure the local main branch to track origin/main.

git push -u origin main

The -u option also configures the upstream relationship during the push. This means you do not need to specify the remote and branch names again for subsequent pushes.

After Configuring Upstream

Once the upstream relationship is configured, Git knows which remote branch the local branch tracks. Therefore, you can simply run git push to send subsequent commits.

git push -u origin main

# Subsequent pushes
git push

This convenience is especially useful when working regularly on the same branch. You only need to specify the remote and branch names when establishing the initial connection.

Practice Set the Upstream Connection

Perform the first push while connecting the local main branch to origin/main. Use the -u option with the git push command.

Starter code

terminal
# Upstream bağlantısını kurarak gönder

Expected output

branch 'main' set up to track 'origin/main'.

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Which option also configures the upstream relationship during the first push of the main branch?

  • -f
  • -v
  • -u Correct answer
  • -d

Explanation: <code>-u</code> is the short form of <code>--set-upstream</code>. It establishes the tracking relationship between the local and remote branches while performing the push.

2 The Long Form of the Upstream Option

Question
git push ____ origin main
Answer
git push --set-upstream origin main

Explanation: <code>--set-upstream</code> is the long form of <code>-u</code> and makes the local branch track the remote branch.

3 Upstream Concepts

Term Meaning
-u Sets the tracking connection
--set-upstream Long form of the -u option
origin/main Remote main branch
git push Pushes to the tracked branch

All lessons in Beginner