Skip to content

Git branch tracking and upstream

Branch tracking (also known as having an upstream branch) is a configuration in Git where a local branch is directly associated with a remote branch. This relationship simplifies workflow by allowing commands like git pull and git push to operate automatically on the configured remote branch without explicitly stating the remote name or branch name every time^[600-developer-tools-git-git-command.md].

Configuration

To establish this relationship, Git provides commands to set or modify the upstream branch for a local branch^[600-developer-tools-git-git-command.md].

Setting the upstream

To configure a local branch to track a remote branch, use the --set-upstream-to option^[600-developer-tools-git-git-command.md].

git branch --set-upstream-to=origin/master master

This command sets the local master branch to track the master branch at the origin remote^[600-developer-tools-git-git-command.md]. An alternative syntax often used in older documentation is git branch --set-upstream branch-name origin/branch-name^[600-developer-tools-git-git-command.md].

Creating tracking branches

When creating a new branch, you can immediately set the tracking relationship using the --track flag^[600-developer-tools-git-git-command.md].

git branch --track branch-name origin/branch-name

Alternatively, using git checkout with the -b flag establishes a new local branch based on a remote branch and automatically sets up tracking^[600-developer-tools-git-git-command.md].

Untracking

To remove the tracking relationship and detach a local branch from its upstream, use the --unset-upstream command^[600-developer-tools-git-git-command.md].

git branch --unset-upstream [branch-name]
  • [[Git]]
  • [[Git Remote]]

Sources

  • 600-developer-tools-git-git-command.md