
We already know part of the answer, based on what we said above: some new objects went into the objects database(s). Saying branch X is ahead of branch Y or branches X and Y have diverged is all well and good, but what does that really mean? If a Git repository is two databases-and it is-what has actually happened in the two databases? How can I do this?Īt this point, we need some kind of understanding of what a branch is. However, the master branch on my fork is ahead of the parent, and I would like to make changes on a branch before getting rid of the changes on my master branch. You would like to resolve this divergence somehow. When that happens with their fork, their repository gets "ahead of" ours. When that happens with our fork (our GitHub repository), our repository gets "ahead of" theirs.

Over time, though, they get unequal, because Git repositories generally have commits (and other objects) added to their commit-and-other-objects databases. So right now, our fork has the same set of branches as their fork. But the clone made by a GitHub fork button copies both. What's in the database-of-names are the hash IDs of the commits (and the annotated tag data, for annotated tags).Ī regular clone, like the one we would make on a laptop, copies all the objects and none of the branches. These names are human-readable and often actually mean something to humans. Separate from the database of objects, there's a database of names: branch names, tag names, and other names. They look random (though they aren't random at all) and they are unpredictable. There's one problem though: the contents are found by their hash IDs, big ugly numbers written in hexadecimal, that are useless to humans. The contents of these objects, particularly the commits, are of interest to humans. These are all read-only: none can ever be changed.
Git create branch from master plus#
There is a database of all "Git objects": commits, mainly, and their supporting objects, plus some stuff for annotated tags. A Git repository consists primarily of two databases: Let's hold off on doing that yet, so that we only have two Git repositories to deal with for now.Īt this point, having pushed the "fork" button, these two clones are identical (except for the added features, but those lie outside Git proper). We can, if we wish, clone either or both repositories to our own laptop or other computer. Both repositories are ordinary Git repositories. Since a GitHub fork is a clone-albeit one with added features-we now have two repositories. You clicked their "fork" button and now you have, under your account, a repository that is a clone of their GitHub repository. You can create a new branch with the help of the git branch command.Let's define a term here (though GitHub do actually define it themselves): the "fork parent" is the repository you were browsing when you decided you wanted to create a GitHub fork. The Operations that can be performed on a branch: Create Branch

So, the git branch is tightly integrated with the git checkout and git merge commands. Many operations on branches are applied by git checkout and git merge command. The git branch command allows you to create, list, rename and delete branches. We can perform various operations on Git branches. It can be called as an official working version of your project. Master branch is the branch in which all the changes eventually get merged back. A repository can have only one master branch. When you start making a commit, then master branch pointer automatically moves forward. When you make the first commit, you're given a master branch to the starting commit point.

It is instantiated when first commit made on the project. The master branch is a default branch in Git.
Git create branch from master code#
So, it is complex to merge the unstable code with the main code base and also facilitates you to clean up your future history before merging with the main branch. When you want to add a new feature or fix a bug, you spawn a new branch to summarize your changes. These branches are a pointer to a snapshot of your changes. A Git project can have more than one branch. It is a feature available in most modern version control systems.

A branch is a version of the repository that diverges from the main working project.
