Git – Branching Operations

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/git-branching-operations/
PINTEREST
PINTEREST
INSTAGRAM

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.

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 - Environment Setup and Basic Configuration

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.

LEARN MORE  Git - Committing Changes To The Repository

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/git-branching-operations/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)