Git – Branching Operations – POFTUT

Git – Branching Operations

Branches are new lines of the current development line. Branches creates new work spaces different from current and changes can be done without affecting current and other branches. After these changes generally branch will merge with the main branch.

For example we want to add new feature. To code the new feature we create new branch and develop our code after being sure we can add this to our app we merge the branch with the main branch.

Listing Branches

Listing branches can be done like below. This will show only local branches where branches resides in local. Remote branches exist in remote repositories.

Listing remote branches can be done like below

Because we have no remote repository there is no remote branch and this command output is not different from previous.

More information about branches can be get with following command by adding -v .

As we see branches uid and last added file is show for detailed information.

Create New Branch

We can create new branch easily like below. Created branch is local and will not pushed to the remote repository.

echo '

As we see we create new branch with git branch test and list branches. Although we have created new branch we did not check the the branch test.

LEARN MORE  Git - Creating Repository From Scratch

Checkout Branch

To start with working test branch we need to checkout it. After the checkout the test branch master branch will not be the HEAD. HEAD is last commit of current work space.

We can create new branch and checkout with single command by providing -b argument.

Rename Branch

Renaming branch is easy as other operations.

Deleting Branch

Branch can be completely deleted like below.

Push Changes to the Remote Repository

We can push a specific branch to the remote repository by specifying remote branch. If the remote branch is do not exists the branch is created at remote. If we do not specify remote repository by default origin is assumed.

Diffing Between Branches

Two branches can be diffed by using diff command.

Leave a Reply

Your email address will not be published. Required fields are marked *