How many types of branches exist in git?
Struggling to understand how to work with remote branches and how many types of git branches there are I somehow got lost in differing namings and git versions. Here’s a few things that happened to me, while believing there are only TWO types of git branches:
- I unwillingly created a non-tracking local branch (so push and pull didn’t work)
- (I therefore decided to abandon automatic push/pull for a while)
- I merged origin/master into my current branch without having fetched from origin before
- I merged master into my current branch without having merged origin/master into it first.
So, after having spent some time mainly at http://git-scm.com/book and on stackoverflow, I got to the conclusion that I can actually describe FOUR instead of the commonly described two types (local vs remote) of git branches. I decided I would try to draw my understanding of how to work with remote branches, I know it is extremely reduced, but the idea would be to point in the right direction and get an idea of the different branch levels:
- git workflow: Can I prevent a certain file from being merged to another branch but still keep it under version control?
- Avoid merging master into development branch
- git workflow branches updates
- Git merge - manual merge - forcing conflic having WHOLE old and new file version
- Git branch unknown to local clone
- will git pull auto merge if pulled from _any_ remote?
Edit: New picture, incorporating dunni’s comment.
What do you think, how much did I get wrong? What should be added/noted?
2 Solutions collect form web for “How many types of branches exist in git?”
You have one error in your picture: The branch origin/master doesn’t exist on the server, it’s called master. The branches on the server are just local branches from the servers POV.
I also wouldn’t distinct between tracking branches and purely local branches, because the branches itself have no differences, other than the little configuration, which would simplify/enable pulling and pushing. But you can also pull to a local branch, which has no tracking configuration, you just need some additional arguments for the pull command.
The branches on the server are not prefixed with
origin is YOUR name for the remote. It’s the default name for a remote but you can name it any way you like. Conceptually
master on the server and your local
master are the same; your machine could easily act as a server for someone else.
Also I wouldn’t distinguish between “tracking” and “remote tracking” branches.
master is the remote tracking branch for the remote’s
master which you have as a copy in a remote branch named
origin/master. You cannot directly manipulate remote branches; only commands that communicate with the remote such as
fetch may perform updates.
There is also no difference between a tracking and what you call a purely local branch. A tracking branch allows some shorthands and lets you omit the remote part in, e.g., merges and rebases. You can do anything without your local branches having to track the remote branches but it is less convenient.