37. Adding a tracking branch


  • 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


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


$ git branch --track style origin/style
Branch 'style' set up to track remote branch 'style' from 'origin'.
$ git branch -a
* main
  remotes/origin/HEAD -> origin/main
$ 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.