Branch

Let’s first take a definition straight from git [1] itself

Branching means you diverge from the main line of development and continue to do work without messing with that main line.

With branches, we can introduce (or reject) new changes into our production branch. We can only have one branch checked out at a time. The currently checked out branch is also referred to as the HEAD branch.

A NetOps example of this would be to clone the repository housing the running router configs. A feature branch could be created to test and develop an improved BGP process. Once designed and tested, this new BGP process can be merged into the production branch. And since this is all in Git, we have the necessary documentation:

  • Who did this?

  • What problem did it solve (commit message)

  • When did this happen?

  • Who approved it?

We can also use compare the differences within Git, making very easy to review.

Commands we will use for Branch

git branch                      { show the working branch }
git checkout <branch name>      { command to switch our working branch }
git checkout -b <new branch>    { creates a new branch }
git checkout -d <branch name>   { deletes branch name }

From module 1 we created our main branch (default branch), let’s verify that using:

git branch

Important

DO NOT MAKE CHANGES IN THE MAIN BRANCH

Now we will create a new branch ‘dev’, this is where we will make our changes and merge them back into the mainline main branch.

git checkout -b dev

This will create a branch locally, we’ll now add a README.md to our dev branch.

vim README.md

And now insert some text

This is a readme file

Once that file is created and saved, let’s set our up-stream dev branch and commit our file

git add README.md
git commit -m "new readme"
git push -u git@gitlab.com:username/ansible_lab.git dev  # make sure to use your username

Now we can verify our new file and branch are present from out Gitlab page

../_images/devb.png

Fig 2

Footnotes