quickblueblur
quickblueblur

Reputation: 286

I need clarification on git local and git remote

The git repository I'm working on has branches for each version of software. 3.1.1, 3.1.5, 3.5.2, etc. There are also branches such as develop which also have an origin counterpart origin/develop.

I noticed that the version branches (among other branches) do not have an origin counterpart.

From what I understood, origin was the remote and non-origin was local. However, I can pull the non-origin branches from the repo as well. So it looks like my understanding is lacking.

The reason I noticed this is I was doing a rev-parse on the local version and comparing to remote. However I can't do this if there's no origin.

So my question is, what's the deal with the branches that do not have an origin counterpart. I can push them to origin using git push origin <branch>, but I'd like to understand the difference before I do that.

Upvotes: 0

Views: 36

Answers (1)

padawin
padawin

Reputation: 4476

origin is a remote (location)'s name, it is like a path. It is the default name of the "original" repository that you clone. But the name is fairly arbitrary. This and the branch name "master" became standard names, but they could as well be named "default-repo" and "default-branch".

A branch (local or remote) is a pointer to a commit. Effectively, in the .git folder, each branch will have a file with the branch name as file name and the hash commit it is pointing to as file content. You can find all your local branches in .git/refs/heads/.

When you push a branch to a remote (origin for example), it will create this pointer file in the .git folder of the remote, and will create in your clone a similar file to represent your clone's knowledge of the remote. This representation of remote branches lives in .git/refs/remotes/<remote-name>/

Then, regarding the "counterparts" you are talking about, any of your local branch can (but does not have to) be linked with another branch (remote or not). When a local branch is linked to a remote, you can see it for example in the .git/config file of your clone, in a section like:

[branch "test-padawin"]
    remote = origin
    merge = refs/heads/test-padawin

Linking a branch with a remote gives some ease with pulling and pushing, as it will then allow you to just run git push or git pull without mentioning where to pull from or push to.

In a nutshell, a branch is a bookmark to a specific commit and to ease work and communication between clones of a repo, they can keep track of their "equivalent" in other clones/repos.

Upvotes: 2

Related Questions