37. Adding a tracking branch

Goals

  • Learn how to add a local branch that tracks a remote branch.

Branches that start with remotes/origin belong to the original repository. Note that you don't have a style branch anymore, but Git knows that it was in the original repository.

01 Add a local branch tracking the remote branch

Run

git branch --track style origin/style
git branch -a
git log --max-count=2

Result

$ git branch --track style origin/style
Branch 'style' set up to track remote branch 'style' from 'origin'.
$ git branch -a
* main
  style
  remotes/origin/HEAD -> origin/main
  remotes/origin/main
  remotes/origin/style
$ git log --all --graph --max-count=2
* 71df43a 2023-11-28 | Changed README in original repo (HEAD -> main, origin/main, origin/HEAD) [Alexander Shvets]
* 39a1e0f 2023-11-28 | Renamed hello.html; moved style.css (origin/style, style) [Alexander Shvets]

Now we can see the style branch in the branch list and log.