Branches provide independent areas for developers so that each can work on its own branch. Each branch represents a different function or feature, separate from the main branch. This allows different teams or developers to develop different features at the same time and track changes without conflict.
The main branch represents the most up-to-date and stable version of the project. When a new feature is added or a bug is fixed, developers work on their own branches without changing the main branch. These changes are then integrated into the main branch, a process called “merge”. This allows developers to develop efficiently without affecting each other’s work.
Let's do an example together;
- In the first step, we go to our github profile and create a repository.

- You need to clone this repository to our own computer.
To clone, you need to use the “git clone” command.
- Open the project on your computer with an editor such as VS Code.
- I create a web page by creating a file named index.html and adding an h1 tag to it.

- I send the file I created to my main branch (master) by running the following commands in order.
# We say to stage all changes.
$ git add *
# We enter a description for the changes we have taken to stage and send them to the queue.
$ git commit -m 'initial commit'
# We send the changes in the queue to github.
$ git push
- Now let's change the h1 tag in the index.html file we created and send it to a branch. First, I change the text inside the h1 tag. Then I want you to apply the following commands in order.
# We create a branch named "first-branch".
$ git branch first-branch
# We send the information for the branch we created to be created on github.
$ git push --set-upstream origin first-branch
# We get a list of branches to see which branch we are on.
# The one with * at the beginning represents the branch we are on.
$ git branch
# We switch to the branch we opened.
$ git switch first-branch
# We put the changes we made on stage.
$ git add *
# We add a description to the changes we put on stage and put them in the queue.
$ git commit -m 'Change index.html'
# We send the changes in the queue to github.
$ git push
- You can log in to your Github account and observe the branch you created. The index.html content in your main branch will not be the same as the information in the branch you created.
- Now let's merge the branch we created with our main branch.
# Let's see which branch we are on.
$ git branch
# If we are not on the main branch, let's change the branch.
$ git switch master
# Merge commandWith the merge command, we get the changes
# we made to the current branch, that is, the main branch.
$ git merge origin/first-branch
# We send the changes we received to the main branch.
$ git push
- You can observe the changes you made both in your code editor and on github.
I tried to explain and illustrate the concept of branching in a simple way, I hope it was helpful to you. 🙂
Good luck with your work…