Tracking a Branch
In general, branches have nothing to do with each other. However, a local branch can be set up to "track" a remote branch. This is very useful in two ways:
(A) Commits Ahead / Behind
If a tracking connection exists, Git can inform you if one branch contains new commits that the other one doesn't have:
- If your local branch contains commits that haven't been published / pushed to the remote repository, your local branch is "ahead" of its remote counterpart branch by some commits.
- If your teammates, on their part, have uploaded commits to the remote, the remote branch will have commits that you haven't downloaded / pulled to your local branch, yet. Your local branch is then "behind" its remote counterpart branch.
In the sidebar, Tower visualizes this by placing a little badge next to the local branch. Simply keep the mouse pointer over the badge to see a tooltip with more information.
(B) Default Target for Push & Pull
By default, Git's Push and Pull commands expect us to provide a couple of information:
- which remote repository we want to push to / pull from
- which remote branch on that repository we want to push to / pull from
However, with a tracking connection set up, something like a "remote counterpart" branch exists for our local branch. In that case, Git already knows where to push to / pull from - and Tower can automatically suggest the correct branch & remote in the corresponding dialogs. This means you will hardly have to make any adjustments when pushing / pulling in Tower and can instead simply confirm these dialogs in most cases.
If a branch is only behind it's remote, you can right-click it to fast-forward and get all the changes without checking it out before.
Track a Branch in Tower
In all dialogs that create new branches (be it local or remote ones), Tower offers you to create a tracking connection between the local and remote branch.
In case you want to explicitly create or change a tracking connection for an already existing branch, you can do so by right-clicking the branch in the sidebar:
- if you clicked a local branch, you can select which branch it shall track or even remove the tracking
- if you clicked a remote branch, the option will create a new local branch that automatically tracks the clicked remote branch.
Read more about tracking connections in our learn section.