Adding a Tracking Branch

Goals

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

The branches starting with remotes/origin are branches from the original repo. Notice that you don’t have a branch called greet anymore, but it knows that the original repo had a greet branch.

Add a local branch that tracks a remote branch.

Execute:

  1. git branch --track greet origin/greet
  2. git branch -a
  3. git hist --max-count=2

Output:

  1. $ git branch --track greet origin/greet
  2. Branch 'greet' set up to track remote branch 'greet' from 'origin'.
  3. $ git branch -a
  4. greet
  5. * master
  6. remotes/origin/HEAD -> origin/master
  7. remotes/origin/greet
  8. remotes/origin/master
  9. $ git hist --max-count=2
  10. * b39ac69 2020-06-20 | Changed README in original repo (HEAD -> master, origin/master, origin/HEAD) [Jim Weirich]
  11. * e0cc19e 2020-06-20 | Updated Rakefile (origin/greet, greet) [Jim Weirich]

We can now see the greet branch in the branch list and in the log.