How to Create Branch in Git

Aakar
4 min readJun 27, 2020

--

On — What is git branch system & it’s working and How you create a git branch system for you ?

Git Branching System

git is one of the precious gems for developer. But the condition is that how you use it .

if you have problem in installing git you can first check out — Installation of Git (For absolute Beginners)

Installation of Git (For absolute Beginners)

Now, that you have git installed on your Laptop / pc, you are now ready to Dig the gem out of a mountain.

The main question, that arises is — what is git Branching System ?? so → git branching is :

A branch in Git is simply a lightweight movable pointer to one of the commits. As you start making commits, you’re given a master branch that points to the last commit you made.

Every time you commit, the master branch pointer moves forward automatically. Note. The “master” branch in Git is not a special branch.

Git allows you to create a branch rather than a master branch so to make you eligible to generate a pull request in the master branch with your updated changes in a separate branch and,

That allows the master, The ability to merge the changes in its own branch i.e the master branch. if he or she is satisfied with your changes

git is not just a software , it’s a whole System in a Nutshell.

Now , let’s have a look at its working !!

Creating a New Branch

What happens when you create a new branch? Well…. doing so creates a new branch for you to move around in the same Structure .

Let’s say you want to create a new branch called myfirstbranch . You do this with the git branch command:

 git branch myfirstbranch

this will create a new branch in your existing git folder or existing git repository.

if you want to create a branch in some other repository , first pull that repository by

git pull repository_URL

to create a branch in that repository type the following:

git checkout branch_name

To check that your branch has been created or not , type the command

git branch 

list your branches. a * will appear next to the currently active branch

Now , you can make the changes you want to make in the pulled repository and you will be eligible to make a pull request for your changes, which has been made.

if you want to switch to another branch and check it out into your working directory , you can use this command :

git checkout

Tips: To show all commits in the current branch’s history , Type the command

git log

Merging of branches

To merge the specified branch’s history into the current one type the following command :

git merge [branch]

After all changes have been made , Now you are ready to push the changes in the online repository , but before don’t forget to commit the changes first

now push the changes by typing the command →

git push --set-upstream origin Branch_name{ To add branch into your own repository}

— To Push changes into some other person’s repository

git push repository_URL

Now you have Successfully pushed your code into the online repository with all the changes

Conclusion

I believe until now you must be ready to do some experiments with git branching system .

--

--