track a remote branch git code example

Example 1: github set branch upstream

git push --set-upstream origin <remote-branch>

Example 2: git checkout remote branch

# In modern versions of Git, you can checkout the remote branch like a local branch.
git checkout <remotebranch>

# Older versions of Git require the creation of a new branch based on the remote.
git checkout <remotebranch> origin/<remotebranch>

Example 3: git local branch track remote

git branch --set-upstream foo upstream/foo

Example 4: git link local branch to remote branch

git config remote.origin.fetch '+refs/heads/*:refs/remotes/origin/*'