Git Branch

Git Tutorial

Git and GitHub

Git Contribute

Git Advanced

Git Undo

Git Branch

Working with Git Branches

Git branches are defined as new/separate versions of the main repository.

Without Git:

  • Create copies of all the relevant files to avoid impacting the live version.
  • Start working with the design and find that code depends on code in other files, that also need to be changed!
  • Generate copies of the dependent files and assures that every file dependency references the correct file name.
  • Save all the file and keeps a note of the names of the copies that the user is working on.
  • Updating the code in case of an unrelated error is found in the code to fix it.
  • Going back to the design, and finishing the work there.
  • Making sure that the updated design is on the live version by copying the code or renaming the file.

With Git:

  • Edit the code directly without impacting the main branch with a new branch called new-design.
  • Generates a new branch from the main project known as small-error-fix.
  • Fixing the unrelated error and merging the small-error-fix branch with the main branch.
  • Back to the new-design branch, and finish the work there.
  • Merging the new-design branch with the main.

Branches allow working on different parts of a project without any impact on the main branch.

Once the work is completed, a branch can be merged with the main project.

Switching between branches is also allowed along with working on different projects without them interfering with each other.

Branching in Git is very lightweight and quick.

New Git Branch

Let’s add some new features to the index.html page.

The work is taking place in the local repository, so there should be no interference with the main project.

creating a new branch:


[user@localhost] $ git branch hello-world-images

A new branch called “hello-world-images” has been created.

Let’s confirm the new branch:

[user@localhost] $ git branch hello-world-images* master

It can be seen that the new branch with the name “hello-world-images” has been created, but the * beside master specifies the current branch.

checkout checks out a branch. Moving us from the current branch to the one specified at the end of the command:

[user@localhost] $ git checkout hello-world-images

Switched to branch ‘hello-world-images’

Now the current workspace from the master branch has been moved to the new branch

Open the editor and make some changes.

Notice: ob_end_flush(): failed to send buffer of zlib output compression (1) in /home/u212091429/domains/ on line 5420

Notice: ob_end_flush(): failed to send buffer of zlib output compression (1) in /home/u212091429/domains/ on line 5420