I have a repository on Github with 2 branches: master
and develop
.
When I clone the repository and run $ git branch
it shows only
git clone
first creates a new empty repository. (like git init
)
It then sets the given repository as a remote called "origin". (git remote add
)
The main work is then done by git fetch
, which is the only command talking to other repositories. It transfers all commits of the remote repository to the current repository and creates inside your local repository branches starting with "remote/origin/" corresponding with the branches on the remote repository.
If you have a default non-bare repository, it will also call git checkout
to checkout usually the master branch.
If you call git branch -r
it will show you the "remote" branches, i.e. those branches in your repository, which will get updated by git fetch
. (You never work on these directly.)
Whenever you want to work on a branch you use git checkout
which will create a copy of that branch, without the "remote/origin/" prefix. Those are the "local" branches on which you work. (git branch
will show those.)
Almost everything you do will involve only your local repository. The only exception is git push
, which is the only command to update remote repositories, and git fetch
which is the only command to query other repositories.
git pull
is just the combination of git fetch
and git merge
. The first fetches changes and updates remote/origin/* and the second merges those changes into your local branch.