3 min episode 19 of 24
Today, we’ll talk about the concepts behind sharing your data on a remote repository.
First, it’s important to know that local and remote repositories are independent from each other. A remote repo is NOT simply a copy of a local one (or the other way around). Both keep their own sets of branches, tags, and commits.
This also means that all the branches in your local repository are - by default - private to you. You decide yourself which branches you want to publish.
For example, you might decide to share your local “feature/login” branch. And another developer might decide to share his “feature/forum” branch. Both are then available on the remote for all team members. Also, a team normally agrees to keep a set of general branches shared - like a “master” and a “development” branch.
In theory, local and remote branches have nothing to do with each other. They’re separate objects in two independent repositories. However, it makes a lot of sense to establish a 1-on–1-connection between them.
This shows in their names, for example: it’s a good convention to name the remote branch exactly like the local one. To make clear it is its counterpart.
And you should even go one step further and really establish a connection in Git. A so-called “tracking” connection. With such a relationship in place, Git will inform you if one branch contains new commits that the other one doesn’t have. Here’s an example:
If your local branch contains commits that you haven’t published (or pushed) to the remote repository, your local branch is “ahead” of its remote counterpart branch.
On the other hand, if your teammates have uploaded commits to the remote, the remote branch will have commits that you haven’t downloaded (or pulled) to your local branch, yet. Then, your local branch is “behind” its remote counterpart branch.
This is valuable information. But Git will only inform you if a tracking connection is set up between the two branches.
Another advantage of a tracking connection comes into play when you actually push or pull changes. Normally, you have to tell Git explicitly to which remote and which branch you want to push (or from which to pull). However, with a tracking connection, Git already knows from where to pull and where to push to: the tracked branch.
In our following videos, we’ll talk about how to establish these connections - and, most importantly, how to finally exchange data by pushing and pulling. See you soon!