Version Control

Version Control is the management of changes to documents, computer programs, large websites, and other collection of information.

Version Controls keeps track of all the version of your project, every small change create a new version of your project

For example : You may have a Java code, and now you are saving the file as, after a couple of days, you feel like some code has to be changed, so you performed that changes. After a week, you realize that you made changes to some other rather than the required file.

What happens now, your job and the code you developed both are gone.

To avoid such kind of scenarios, a tool takes a back up of your code, every time there is any change.

The tool which handles the above backups are called as Version control tools, I have listed few below:

  • GIT [ we are going to explore ]
  • SVN
  • Bazaar
  • Mercurial

Tools to Improve Java Code Quality

Git software

Git is a version control system for tracking changes in computer files and coordinating work on those files among multiple people.

Git is distributed control system

It is primarily used for source code management in software development, but it can be used to keep track of changes in any set of files.

Git is an open-source program to keep track of changes in your files. It just takes screenshots of your files when you save them, and then it compares the files for differences.

Install Git :

  • Navigate to
  • Choose the to download based on your operating system [ I am using WIN 10]
  • Open the installer and follow just standard procedure, do not change any
  • If you want you can bring the git shortcut to Desktop

User Details in Git

Setting user details like user name and email is important for tracking purposes; follow below commands to set details.

Before setting any values in git, you need to open git bash terminal, --global is nothing but the scope of the user details.

Set the user name to the git

git config --global "karthiQ"

Verify the user name that you had set

git config --global

Set the user email address to the git [ to follow this tutorial, you can use gmail account as well ]

git config --global "[email protected]"

Verify the user email address that you had set

git config --global


Page Object Model Folder Structure

Basics of Git CMD :

It is important to learn command line/CMD commands in git, even though we may not use them along without modern work IDEs but they will be helpful

Get the current folder details:


Create a new folder,

mkdir folderToCreate

Move into a sub-folder:

cd folderName

Create any file and save it in the folder that we have created just before; in the below step, I am using the vim to create a file.

Create a file in git:

touch abc.php

List the files in the current folder


Remove/delete a file:

rm abc.php

Step out of the current directory:

cd ..

How to remove a directory:

rmdir directoryName


Create a Git Repository :

Create a folder called SampleRepo and move inside the folder for creating the git repository

Convert the created folder into the git repository with the below command.

git init

if you see the highlighted line in the output, then your repository got created successfully.

Create two files inside the repository using the touch command

touch abc.php

git status :

git status command shows the difference between the working folder and the local repository, just because we have created above two files in the current directory does not mean they are present in the local repository. Those two files are just present in the working directory, even though the working directory and local repository are the same.

Files will be moved to the local repository only when we commit them to the local repository.

The untracked files are nothing but the files that you have created but not committed.

$ git status

On branch master
No commits yet
Untracked files:
  (use "git add ..." to include in what will be committed)
nothing added to commit but untracked files present (use "git add" to track)

AutoIt in Selenium

Stage the files :

The stage is nothing but the pre-step for committing the files, Committing files staging is important.

We can add files to the stage using add command in the git.
git add abc.php
[email protected] MINGW64 ~/SampleRepo (master)
$ git add abc.php
[email protected] MINGW64 ~/SampleRepo (master)
$ git status
On branch master
No commits yet
Changes to be committed:
  (use "git rm --cached ..." to unstage)
		new file:   abc.php
Untracked files:
  (use "git add ..." to include in what will be committed)

You can differentiate the added and not added/untracked files

How to remove a file from the stage

git rm --cached abc.php

We can add all the untracked files into stage using .(dot) command

git add .


Commit the files to Local repository :

Committing is nothing but adding our staged files into local repository

Committing is important, and you should commit whenever you feel like you have completed a unit.

commit command is used to commit the staged files, we can also set the message for the commit, messages could be your simple description of the changes, -m represents that following is a message

git commit -m "added two basic files"

commit outcome

[email protected] MINGW64 ~/SampleRepo (master)
$ git commit -m "added two basic files"
[master (root-commit) c9979a2] added two basic files
 2 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 abc.php
 create mode 100644 index.html

we can see the commit history by using log command, this will tell us what branch we are in and the author, date, commit message.

git log

The outcome of the log, HEAD represents, to which repository user committed.

[email protected] MINGW64 ~/SampleRepo (master)
$ git log
commit c9979a285091d7a4f2a35382a071c84b98bdfaee (HEAD -> master)
Author: karthiQ
Date:   Sat May 19 02:37:01 2018 +0530
	added two basic files

CSV Files with selenium


A branch is a mirror of your current repo. When you branch, your current repo (usually your main branch) goes untouched. This is great when you want to create a feature in your application because you do not have to worry about breaking a working application since

The branch is nothing but an independent line of development. For example : People create dev branches from the Master Branch. Now developers will do all the edits or features in the dev branch. After the edits or developments of a feature are completed, then one after testing the dev branch will be merged into the master branch.

We can create a check the branches present in the git using git branch command; if we provide a new name along with the git branch, it will create a new branch.

The branch that we are currently in will be in a different color with an * asterisk in the front.

[email protected] MINGW64 ~/SampleRepo (master)
$ git branch
* master

Create your first Branch:

[email protected] MINGW64 ~/SampleRepo (master)
$ git branch
* master

Switch to the newly created branch :

[email protected] MINGW64 ~/SampleRepo (master)
$ git checkout FirstBranch
Switched to branch 'FirstBranch'
[email protected] MINGW64 ~/SampleRepo (FirstBranch)
$ git branch
* FirstBranch

Now, if you create any files, it will be created in a new branch only.

Git Ignore :

Sometimes you may have files that are related to the execution or some log files; these files are to be omitted when we push our source code.

Let's create files: report.log, error.log in our current working folder. With git status command you can see tracked and untracked files,

[email protected] MINGW64 ~/SampleRepo (FirstBranch)
$ git status
On branch FirstBranch
Untracked files:
  (use "git add <file>..." to include in what will be committed)
nothing added to commit but untracked files present (use "git add" to track)

Now in the above thing, we always get to see these useless log files in our untracked work, if we have two log files we do not have many issues but if we have hundreds of log files, then it will create bigger confusion, to avoid this kind of situation we can use git ignore.

When we want to ignore the files we have to make an entry of those files in .gitignore Below is content that I have created in .gitignore file, we can use # symbol for commenting.

#.gitignore file content

We can also ignore files based on regex, below file content ignores all the log files.

#.gitignore file content

If we try to see the tracked and untracked files, then we will not have those log files as part of untracked files.

[email protected] MINGW64 ~/SampleRepo (FirstBranch)
$ git status
On branch FirstBranch
Untracked files:
  (use "git add <file>..." to include in what will be committed)
nothing added to commit but untracked files present (use "git add" to track)
Just creating a .gitignore file will not help us; we have to commit the .gitignore file so that it will become active


Merge is a definition within itself. If you were working on a branch in which you have your working feature built, and you want to merge that feature back to the master branch, you would need to do a merge. It combines them into one.

We use the git merge command to merge two branches.

You should be in a branch, to which you are going to merge some new branch [ here master]

If you are not in a target branch, then you have to checkout to that branch, and then only you should use the merge command.

You should make sure you do not have any uncommitted work in the secondary [FirstBranch here] before merging.

[email protected] MINGW64 ~/SampleRepo (FirstBranch)
$ git commit -m "description of change"
[FirstBranch ab72069] description of change
 1 file changed, 1 insertion(+)
 create mode 100644 .gitignore
[email protected] MINGW64 ~/SampleRepo (FirstBranch)
$ git checkout master
Switched to branch 'master'
[email protected] MINGW64 ~/SampleRepo (master)
$ git merge FirstBranch
Updating c9979a2..ab72069
 .gitignore | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 .gitignore


A clone is when you “clone"? a remote repository and receive a local copy for your modification. Git will keep track of all your modifications locally, so you don’t have to depend on the reliability of the server.


A push is how you get your local files to a remote repo so your team will have the option to pull your latest modifications.


A pull gets the latest code from a remote repository. When you do a pull, it also does a merge. A pull is basically a fetch and a merge.


Fetch is a pull without the merge. This is helpful if you want to compare the code your team has put together before deciding to merge it to your local repository.


Checkout lets you navigate between branches.

Learn about Constructors in selenium and Java

Good practices for pushing to the remote repository

  • Make sure to communicate what I am working on with teammates before I start any change or feature to avoid duplication of efforts.
  • Before pushing, make sure I have pulled all current files or changes from the master/remote.
  • Be sure there are no bugs in my current commit, and it is thoroughly tested.
  • Never commit anything that is not complete.
  • Use feature branches for anything but minor changes.
  • Commit often.
  • Use descriptive commit messages, something like “added new file"? is meaningless, “added new JS file for handling login modal behavior", for example, is much better.

Headless browser in Selenium webdriver


BitBucket is a remote repository, which was later acquired by a company called Atlassian ( yeah, the same company that owns JIRA). BitBucket enables the user to use Git and Mecrucial software for integration from local repositories to remote repositories.

Features of BitBucket :
  • Pull requests and code reviews
  • Unlimited private repos
  • Branch comparison and commit history
  • Bitbucket Mac and Windows client called SourceTree; Android app called BitBeaker
  • Bitbucket for Enterprises, called Stash
  • Integration with tools like Jira, Crucible, Bamboo, Jenkins

Create Repository on BitBucket for Free

Bit bucket provides free repositories for the team, which has less than 5 members if your team is bigger, maybe you need to buy some premium stuff.

With free itself, you can create an n-number of repositories, which include private and public.

Steps to Create a Repository on BitBucket :

    • Navigate to
    • Click Get Started and sign up for the bit bucket by providing your email id
    • Enter your username and password
    • Verify your email address
    • Create a unique user name for you
    • Click on Create repository


Apache POI with Selenium Integration

Clone Bitbucket Repository

Cloning repository is nothing but copying the remote repository into our local system, similar to download.

Steps to clone the Bitbucket repository :

    • Navigate to bitbucket repository and click + icon on the left.
    • Select Clone this Repository under get to work
    • It will open a Modal box, in that you can choose how you want to clone your repository either using https or ssh method.
    • I clone via https method
    • Copy the URL that starts with git cloneclone-repository-bitbucket-selenium
    • Paste the URL thing that copied in bitbucket and press enter key/return key


  • Sometimes bitbucket asks to enter the password in git bash itself (password is masked to not appear, so when you enter you cannot see your password, so after entering your password press enter
  • Instead of the above step, sometimes bitbucket shows a pop up to enter password [ with me this is the case]


    • If everything successful then you will see below message


How to install Selenium Grid

Commit and Push to Bitbucket with Git

In the above-created clone folder, let's create few files inside the demorepo; you can create it using file explorer itself.
testfiles-create-into-remoteAdd the files into stage using add command in git and commit using the commit command.

[email protected] MINGW64 ~/SampleRepo (master)
$ cd demorepo/
[email protected] MINGW64 ~/SampleRepo/demorepo (master)
$ git add .
[email protected] MINGW64 ~/SampleRepo/demorepo (master)
$ git commit -m "first commit to remte repo"
[master 87ed4ae] first commit to remte repo
 2 files changed, 3 insertions(+)
 create mode 100644 testfile.txt
 create mode 100644 urlfile.txt

Push the commit into the remote repository using push command.

[email protected] MINGW64 ~/SampleRepo/demorepo (master)
$ git push
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 415 bytes | 207.00 KiB/s, done.
Total 4 (delta 0), reused 0 (delta 0)
   40bd670..87ed4ae  master -> master
Note : In some tutorials, you may see git push orgin master, that is also right, but it did not work.

You can verify the push by navigating into the bitbucket repository in your browser under the source tab.
verify-the-push-to-bitbucketYou can also get the details of the person who committed the change under the Commits tab.

Data Provider in TestNG

Pull the code from BitBucket

When there is more than one person working on a project, we may need to use the files created by other people.

To get the files from the bitbucket, we can use the git pull command. But make sure that other person first pushes the code into the bitbucket before you try for the pull.

As I am the only person working on this, so I am going to create a file in the bitbucket repository for pulling to our local repository.

Navigate to our repository; click the three dots next to the clone button. Select the Add file option and provide name and content.
addfile-bitbucket-gitAdd some name and content to file
demo-pull-file-bitbucketNow commit the file and provide some message for the commit in bitbucket.

Once the creation is done, open your git and use the git pull command.

[email protected] MINGW64 ~/SampleRepo/demorepo (master)
$ git pull
remote: Counting objects: 3, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
   87ed4ae..f4b93c6  master     -> origin/master
Updating 87ed4ae..f4b93c6
 AddFilePullDemo.text | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 AddFilePullDemo.text

At the end of the message, you can see AddFilePullDemo.txt got pulled. You can ensure by navigating to the respective folder in your local system.

Pull command performs two operations 1. fetch, 2. merge.

fetch brings remote changes to the local system.
merge merge the change from the fetch into your local files.

Next, we will learn how to use a UI interface to connect bitbucket and git rather than git bash console.

Event Listeners present in Selenium


SourceTree is freeware, which provides Graphical User Interface for version control software.

By default, git comes with Git Bash console, which looks similar to your terminal/cmd, with terminal handling changes becomes overhead.

To avoid this, we would be using the Graphical UI provided by SourceTree software.

Install SourceTree :

  • Navigate to
  • Download the SourceTree software based on your operating system
  • Agree to the Terms and select to Atlassian account
  • Enter your user name ( we have created on bitbucket), and password for the same
  • If you have not installed or if you want to install some version controls, you can install here

Clone repository using SourceTree :

Once we complete the SourceTree installation, open the source tree software, you see below interface in win 10.
source-tree-bitbucket-gitNow you can clone either local repository or remote repository; I am cloning the same remote repository that we have created sometime back.

Click Clone icon in SourceTree, I hope You know how to take clone URL, please do provide without the git clone and choose a local folder to which you want to download the remote repository.

Once the clone is over, you should be able to see a window similar to below one.

Handle dropdowns in selenium

Basic Operations of SourceTree

We can perform all the operations SourceTree that we had performed using git bash; with SourceTree, we can perform more operations with simple clicks.

Stage Files in SourceTree :

Create a new file in the repository that we have cloned in the above step. I am creating a file called style.css and placing some text inside the file. stage-sourcetree-git-bitbucket We have created a file, and now we can perform the staging operation in SourceTree.

If you open SourceTree, you can see some un-committed changes in the top pane, and the file (style.css) we have created is in the bottom pane under Unstaged files section. unstaged-files-sourcetree-bitbucket-selenium The SourceTree automatically detects the changes in the repository.

To Stage any file, we need to select the file and click stage selected or stage all if you want to stage all the files.


Similar to the stage, we can un-stage the files by selecting a file and then clicking unstage selected, unstage all buttons.

Commit files in SourceTree :

We can commit the files in SourceTree by clicking the commit icon at the top left corner in the SourceTree.

Once we click the commit button, then we have to select the staged files to commit, and provide a description for the changes and press the commit button at the bottom of SourceTree.

Branching in SourceTree :

We can create the dev branch in SourceTree by clicking the master branch and then clicking branch icon branching-sourcetree-bitbucket

Provide the branch name, also select the working copy parent option to get all the details and code from the master. If you want to start working on new, then you have to select 'Checkout New branch' option branch-details-sourcetree-bitbucket

We can verify which branch is currently checked out by looking at the Branches section in SourceTree. The current branch will a have circle at the front of the branch. current-branch-sourcetree-bitbucket-selenium

Merge in SourceTree :

Merge is a headache in any version control tool, because if we remove something that we have not developed, then it may create a scene in the team.

The below example shows the merge of two different branches without any conflicts: Let's add and commit a file in the repository, remember we are working in dev branch now. Do you remember, earlier I said we have to be in the main [master] branch to which we are going to merge some sub[dev] branch.

We are currently in the dev branch, so let's switch to the master branch. We can switch by right-clicking on the required Branch and selecting the Checkout branch. checkout-branch-sourcetree-bitbucket

To Merge the sub-branch, we have to right-click on the sub-branch and select the Merge sub-branch with the current branch ( we already switched to Master branch, so our current branch is master). merge-sub-branch-master-branch

We have seen how to merge without any conflicts, but if we have any conflicts between files, then we have to resolve them, and then we have to merge.

Let's create a branch called complexity from the master branch and edit the content of a file. merge-conflicts-sourcetree-bitbucket

Switch to master and try to merge the sub-branch (complexity) with Master, now will see below pop up. Click Close button merge-conflict-source-tree

Now select the file status tab at the bottom, you can see the file conflicts at the right top corner. conflicts-sourcetree-bitbucket

In the below image, the first changes are with <<< which means that it is the Main branch value.

The second change is with >>> which means this is sub-branch value. conflict-explanation

We have to keep only the change that we want to keep, some editor may give you an option to choose/remove the values, but if you are using normal editor, then we have to remove lines manually. conflicts-removal

Once you resolve the conflicts, then you only need to push the code.

Push the code :

You just need to click the Push icon in the top, it will ask for the branches to push. Select the branches carefully and push it. push-sourcetree-bitbucket

You can verify the pushed code in bitbucket. bitbucket-sourcetree

Pull in SourceTree :

Pull is nothing but making our local repository up to date with the remote repository, pull performs two operations 1. fetch, 2. merge pull-source-tree

If you select rebase instead of merge, then it will remove all the save commits and uncommitted changes in the local repository.

Result of the pull request

Selenium With SourceTree & BitBucket & Git

Now it is time for cooking, so far we have been learning what the raw materials required for cooking are, so let's start cooking.

Steps to push the Selenium Code to Bit Bucket :

    • Create a repository in the bitbucket repository.

    • Open the SourceTree and clone the bitbucket repository into your local

    • Switch your workspace into the sample folder where we have cloned our remote repository

    • Create a sample java project in eclipse and create a few packages and Classes in it, you may see question marks on the file name.

    • Before pushing, you should make sure what are the files you want to push, more specifically, what you do not want in the remote repository. As per me, I want only src folder files, and I want to ignore every other folder.
# .gitignore file

/* ignore everything -> in the current folder.

SeleniumGitSourceTreeBitBucket/jars -> ignore everything under SeleniumGitSourceTreeBitBucket/jars folder

SeleniumGitSourceTreeBitBucket/bin -> ignore everything under SeleniumGitSourceTreeBitBucket/bin folder

!/SeleniumGitSourceTreeBitBucket/ -> donot ignore the files under this folder [ basically consider this folder for pushing]

Folder structure: folder-structure

    • Open your sourceTree, and check the unstaged files, it should match with gitignore

    • Stage the files present in the unstaged list using Stage All

    • Commit the files using the commit icon on the top

    • Before pushing, always take a pull request, now Push the files that we have committed in the last step using push icon at the top.

  • Goto BitBucket repository and check whether push is successful or not, if you see the content you pushed, then push was a success.

How to revert/rollback the push

Reverting is nothing, but you have pushed something into the remote repository, which was not necessary or wrong code or detail.

If it is a change of one 1- 10 lines in the same file means you can change them in your local and makes new push to override the wrong details, but if code affected was huge, then it is better to revert.

For reverting a particular push you need to get the commit id, you can get it from the bitbucket or the sourcetree.

git revert <commit id>
# I am reverting above push.
git revert 1f51b93


If you see bitbucket now you would be still seeing the files; the reason is we have not pushed the reverted files back

Once we execute the revert command, then we will have files unstaged (waiting as removal of change), now stage all files and commit and push them to clear the changes. stage-delete-files

We have to verify the bitbucket that all the changes are removed. revert-bitbucket

About Author :

I am Pavankumar, Having 8.5 years of experience currently working in Video/Live Analytics project.

Comment / Suggestion Section
Point our Mistakes and Post Your Suggestions