chenop chenop - 1 month ago 18
Git Question

Intellij Git - Git vs. Local vs. Remote branches

Very confused regarding Intellij terminology related to Git branches type.
What are the differences between Git, Local and Remote branches?

Here is documentation that refer to those 3 types.

Answer

The documentation you cited describes how to checkout (create) a new Git branch from either a local or a remote branch. I count two things, not three. To make things more confusing, both the local and remote branches are actually local. For the sake of explanation, let's say the branch in question were called someBranch, and it had a local and remote version.

The local branch someBranch is what you would work on when doing your actual development in IntelliJ. For all intents and purposes, this is the branch someBranch.

The remote branch is actually a tracking branch. The remote tracking branch of someBranch would likely be called origin/someBranch by default, or something like that. The remote tracking branch exists primarily to sync up with the remote respository. When you do a git fetch, the remote tracking branch is actually what gets updated. So origin/someBranch would receive all the latest updates from the remote, but the local branch someBranch would not be updated. If you were then to create a branch from the remote branch, you would be using the latest version on the remote repository, and not whatever version you have locally. And there are many scenarios when you would want to do this.