Tracking branches
With Git, a branch can track another branch. This allows you to use the commands pull
and push
, without specifying the branch and repository.
For example, if you clone a Git repository, your local master
branch is created as a tracking branch for the master branch of the origin repository.
To set up a tracking branch, execute this:
Jim@local:~/webproject$ git checkout -b new_branch origin/branch_to_track #Or you can use this Jim@local:~/webproject$ git branch new_branch origin/master Jim@local:~/webproject$ git branch --track new_branch origin/master
Similarly, you can specify to not track a remote branch:
Jim@local:~/webproject$ git branch --no-track new_branch origin/master #You can later update this branch and track origin/master ...
Get Git Best Practices Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.