2.3 Local Branches

Let’s talk about local branches in more detail. (The terminology used here is my own, not official Git jargon.) There are two kinds of local branches:

Tracking Branches

Tracking branches track branches from the upstream repository. You first create a tracking branch simply by checking out a branch from the upstream. You use the branch name without the leading ‘origin/’ prefix. For example, ‘git checkout gawk-4.1-stable’.

You can then work on this branch, making commits to it as you wish. Once things are ready to move upstream, you simply use ‘git push’, and your changes will be pushed up to the main repo.2

You should never checkout a branch using the ‘origin/’ prefix. Things will get very confused. Always work on local tracking branches.

Purely Local Branches

A purely local branch exists only on your system. You may be developing some large new feature, or fixing a very difficult bug, or have a change for which paperwork has not yet been completed.

In such a case, you would keep your changes on a local branch, and periodically synchronize it with master (or whichever upstream branch you started from).

This may seem somewhat abstract so far. We demonstrate with commands and branches in Development Without Commit Access, later in this Web page.

Let’s say you have checked out a copy of gawk-4.1-stable and have created a purely local branch named better-random. Then our picture now looks like Figure 2.3, where the ‘T’ column indicates a tracking branch.

+===+======================++=============================+
| T |   Local Branches     ||      Remote Branches        |
+===+======================++=============================+
| X | master               || origin/master               |
+---+----------------------++-----------------------------+
| X | gawk-4.1-stable      || origin/gawk-4.1-stable      |
+---+----------------------++-----------------------------+
|   |                      || origin/gawk-4.0-stable      |
+---+----------------------++-----------------------------+
|   |                      || origin/feature/fix-comments |
+---+----------------------++-----------------------------+
|   |                      || ...                         |
+---+----------------------++-----------------------------+
|   | better-random        ||                             |
+---+----------------------++-----------------------------+

Figure 2.3: Your Local gawk Repository With a Purely Local Branch


Footnotes

(2)

Assuming you have permission to do so, of course.