Start Git With NO Effort — 2…!

In this second article, let me try to answer some of the questions popped at the end of the last article.

Let’s start with questions related to the repository. In context of version control system (vcs), here git, the repository is centrally located on some server where the code is made available to other team members. Now one must be wondering about, how git is distributed when it is made available centrally. It was already answered in my last article, would elaborate a bit here. When the repository is cloned on one’s machine, the clone maintains the copy of central repository on the local machine. It contains all the metadata, present in a central repository. One can say its replica of central repository.

Hence, there are no bifurcation or types of repository. But there is a tweak too. The new term I would like to introduce here is “fork”. In simple words, fork is a copy of the main central repository and it is also at the same central location, but not accessible by all who has access to the main central repository. This is because, the owner of the fork decides the permission of fork created by that particular member/owner. Every member who has access to main repository can create their own fork(s), but the permission to create fork by the users must be enabled by main repository owner/group of owners. Enabling of fork creation is configured at the repository level and not at the individual user level.

To summarize fork, one can say it is a named repository created by cloning at server-side and can be used/accessed in the same way as a main central repository. This can also be made available others on access basis.

Why fork? I guess this is the new question which is popping right now. The fork has many use cases. I’ll try to list a few of them here:

  1. When there is some research work to be done in parallel to existing development without affecting normal/routine development cycle.
  2. When there is a huge project with large modules within a single product. The different teams create their own fork and work on individual modules and keep their fork in sync with the main repository.
  3. In some organizations, they define the structure of projects for development and configuration. So the skeletal of same is created as a main repository and all the succeeding projects are forked out of that main repository.

NOTE: Fork creation and configuration related process can not be done on GIT Bash Command Line Interface, it needs to be carried out on the server side where the main repository resides. Example: bit-bucket, Github, GitLab, etc.

Here I conclude the basic concepts of repository and forking of the repository. Now, let us start with branch concepts to get answers related branch.

What is a branch? Branch is a reference to commit.

Let’s understand it now. It is a physical entity to point a logical entity. Here logical entity is commit. When a repository is created, the default branch is master. This branch is the root of the repository and has at most importance.

Never work on master branch.

When a new repository is created, the admin creates various branches and permissions for those branches to the team members. These branches are available in the repository and that is on the remote. Hence the branches at remote repository is called remote branch.

Now one must be wondering that, if I clone the repository, then those branches of my local system are still remote branches or something else…! The answer is, those branches on your local machine are still remote branches.

Never work on remote branch.

So now arise a question, how to create a branch? It’s very easy to create a branch and list the same.

git branch <branch_name>

git branch -a

The above commands will just create a branch and list all the branches, respectively. Here all branches means, the local (aka feature) branches and remote branches.

NOTE: The commands for different operating systems differs a bit with respect to different available flavors.

Now it’s time to spend time to understand some commands related to branch. Think upon some commands and operations on branch and checkout the part 3 of this series.

Please post your queries, comments and topics that need clarity in current article. Most importantly, correct me if any information is misleading or incorrect. Lets learn together…

Part 2 Concludes here…

Freelancer