Creating a branch in Git: Branch refers to a version of repository which diverges from the major working projects. It’s a feature accessible in a more modern version of the control systems. Git makes managing and creating branches simpler. The power & flexibility of the branching model is among the biggest benefit of Git. Git projects can consist of more than a single branch. Branches are a pointer for a snapshot of the changes. When a new feature needs to be added or fixed a bug, spawns some new branch to summarize the changes. Therefore, it’s difficult to merge unstable code with a major codebase & facilitates one to clean up upcoming history.
How to Creating a branch in Git?
There are a few methods in which one can create new branches at Git, with more of them different in how the branch is made from a major branch, whether this can be from the current branch, a tag, a different branch, etc.
The major common way of creating a new branch is
That’s the most widely used syntax because it creates a branch for you from the current branch & it switches you to the branch in a single command.
Moreover one can also specify various branches from which new one will be made:
Another different way is through using branch command directly.
As seen from the example below, this does not automatically switch over to a new branch & keeps us on the current one:
When you need to work on a branch directly then you are required to switch to it yourself using the checkout command:
Creating Branch from Commit
There are other few ways in which one can make new branches. One of these ways is through specifying a precise commit through its hash:
As always when using Git, the whole hash does not require to be precise, just a few characters.
One can also utilize syntax, which will git create branch & check it out, wholly in a single command.
Creating Branch from Tag
This method is particularly useful as tags can be an excellent way for referencing a certain point in some project’s history.
syntax can also be used
Creating a new branch from a remote branch
Here you need to take a remote branch as a basis for a new local branch, you can utilize the “–track” option:
Moreover, one can also utilize the “checkout” command. When you need to name a local branch alike the remote one, all you need to have is to specify the name of the remote branch:
Creating a new branch in a remote repository
After operating on a new local branch, you may need to publish it in a remote repository, for sharing it with the team:
“-u” flag informs Git to institute a “tracking connection”, which will make pulling & pushing easier in the future.
Git Master Branch
Master branch refers to a default branch at Git. It’s instantiated when the first commit is created on the project. When one makes the initial commit, you are given a master branch to begin the commit point. When one begins making some commit, the master branch pointer auto moves forward. Some repository just has one master branch.
Here at the master branch all the changes finally get merged back. This can be known as an official working version of the project.
Operations on Branches
On Git branches various operations can be performed. The git-branch command enables one to create, list, delete or rename branches. Other operations at branches are used by git checkout & git merge-command.
Other Important Topics
- Data Manipulation – Understanding Data Manipulation | HTML KICK
- What does ftp stand for?
- Difference between Python and Java | HTML KICK
- How to link JavaScript to HTML?
- 10 Differences Between llama vs alpaca | HTMLK KICK
- Cyber Awareness Challenge Questions and Answers