Brief about Git, Git Flow, Git Branching
What is Git?
Git is an open-source version control system. Git lets us keep track of changes made to a project’s file using simple commands. During the development process, the project contains several points, which refers as commit. All the changes implemented in the project from the previous commit are stored in the commit history. From the history, the user can access different versions of the project.
How does Git work?
Git works by saving the last state (snapshot) of your project. Git keeps files that have been changed or created since the last snapshot. For this Git uses the SHA-1 hashes of each commit to identify it. Hash, which serves as the key to a certain commit in the repository, is essentially a form of a unique ID. One commit is referenced by one ID. There is no room for ambiguity.
To store and retrieve your data and its metadata as quickly and effectively as possible, Git frequently builds references to other references in a tree-like structure.
What are Git states?
Git has three primary states.
- Working directory — When we do change in the local repository it creates a working directory.
- Staging directory — After the change when we give the git add command it creates a staging directory.
- Committed — After adding the change when we add the git commit command, the file or project becomes committed. And it is permanently added to the local repository.
There are many terminologies we hear like git flow, git merge, git branch, git fetch, etc. Here in this article, I will talk about what I know about git flow and git branch.
What is the Git flow?
Git flow is a branching model based on git. This great advantage is that more than one developer can work on a big project without disruption.
Git-flow configure
To configure git-flow, you first need to have a git repository. When we git init a project, all the commits are stored in a default branch “master”.
Now we will follow some steps:
1. First we will create a folder:
mkdir git-flow-test
2. Now I will create a file in the git-flow-test folder.
cd git-flow-test
touch test.txt
3. Now we will first create the git repository here. For that we will run the below command here:
git init
4. Now we’ll commit our changes to Git. For that, run the following commands:
git add git commit -m “commit message”
5. Now all our changes are in Git’s primary branch master. Now our git repository is ready to build git-flow. Now we will run the following commands to build git-flow:
Git-flow feature
Before we start the git-flow feature, we’ll make a few things. For example, before we do any project in a project management system, we write all the features, bugs, etc. related to the project in detail. Then we assign it to different developers.
Suppose our project name is Hello Git-Flow
we have the following features:
- HGT-01: Hello Git-Flow project
Now, we will start working on the features one by one, using the git-flow feature.
- First of all, we will start working on the HGT-01 feature. For that, we will write the command
git-flow feature start HGT-01
2. Now we will work on feature development and make incremental commits, just like we used to commit in git. Any changes we make will continue to be added to our current feature branch. We will add the file to git and commit it to git.
git add .
git commit -m "project configuration file is added"
3. Now our feature development work is over. Now we will complete our feature with git-flow
git-flow feature finish HGT-01
Git-flow feature publish
If we think someone else will be working on a feature branch, we can upload it to Git if we want. For this we will run the following command:
git-flow feature publish HGT-01
Git-flow release
Another essential command of git-flow is git-flow release. With this, we basically create a release from a development branch to the production server. With this, we can very easily give the number of a release, so that we can easily back it to the next release.
If we want to know the git-flow release syntax, we can go to the command line and type the following command:
Git-flow release (press enter)
There are three terms to know:
1. <name> : name of the release. For example rel-v1.0
2. [<base>]: This is a branch name. Means if we do not create a branch from the development branch, but want to create a release from another branch, then we will give the name of that branch.
Now we will create a release. We assume that our branch development. Then run the following command without delay:
git-flow release start rel-v1.0
We now see a new branch created called rel-v1.0.
What is the Git branch?
When we want to add a new feature to our project. For this, a new working directory is created without directly updating the code in our main project. That’s what we call brunch. Here we test by adding new features to the project and if everything goes well, merge it into the main project. Git branches allow working on projects independently. If we create a branch in a project, the history/record of the new work we do will be included in this branch. We can create/rename/delete new branches using the git branch
command.
Why is Git used?
Since Git is a version control software, the version of any software can be easily controlled through Git. With Git, different developers can participate in the development of the same software, make changes, and a specific developer can finalize those changes. Since Git is a distributed version control system, it can also be used as a server. A dedicated Git server software helps in adding access control, displaying Git repository content over the web, and managing multiple repositories, among other features. Although Git was primarily developed for Linux, it also supports most other operating systems, such as Windows, macOS, etc.