Version control with Git: tracking remote branches

When you clone a repository, Git only creates a branch corresponding to the remote's master. For each other branch that exists at the remote that you wish to work on locally, you need to create a local branch to track the remote branch. You can do this with:

git-checkout --track -b mybranch origin/mybranch

Subsequently, when you work on branch mybranch, git pull will know to acquire and merge changes from the specified remote branch.

2 comments:

  1. What about "git push"?

    ReplyDelete
  2. Yes. When you are on your tracking branch, "git push" will push changes back to the remote branch being tracked.

    ReplyDelete