How To Create Branch In Git Repository On Linux 7

Create a branch in git using Gitlab is an Open source web-based git repository that will provide you issue tracking, wiki & CI/CD pipelines. I have already setup git-lab on my machine. If you do not know how to install git-lab you may follow this article. when you need to change the branch we have to run the git checkout branch.

How To Create Branch In Git On Linux:

We can easily create a new branch in git using the command line and push them to either GitHub or GitLab server. The process is similar to create a branch in Github and GitLab.

Branching Concept:

If you want to work on files where you don’t want to send these files directly to the master branch. So it’s better to create a new branch where you can work and after testing the code, you can push all the files from newly created branches to a master branch.

Check Out: Install Gitlab

Step 1: First you will have to add the remote origin in your git repository.

Step 2: Create a Branch failure

This branch, you can test your code and later merge in the Master branch.

Step 3: Checkout branch, It means if you want to work in this branch you have to use the checkout branch command.

Check Out: Error 502 While accessing the Gitlab

What’s the benefit of this?

If you work in another branch except for Master, whatever you made changes in your repository it will not affect the master branch when you push the code to the remote machine. So, this is the main reason we make branches in git.

My branch name is failure

Step 4: Now create a file and add commit the file.

Step 5: Now Checkout to Master Branch

Check Out: How To Merge Branch In Git On Gitlab

Step 6: As you can see in my testing repository, There is only one file is present.

create branch in git

Step 7: Now you have to push the code which you have written in the failure branch

branch in git

it will send the code to the failure branch only.

Step 8: Here I will show you there’s a two branch one is Master & another one is a failure, So select to failure here to see files has been reached or not.

Check Out: LDAP Authentication With Gitlab Server

create branch

By default, the Master branch will be selected

Step 9: As you can see there is a file in the failure branch

branch create git

You’re done git checkout branch

Share on:

I'm the founder of Curious Viral. I hope this blog will provide you complete information about Linux Technology & I would like to share my technical knowledge with you which I have learned during this period.

Other Posts You May Like...

Leave a comment