What is Git?
Git is a Distributed Version Control System (DVCS) used to track changes in source code during software development. It allows multiple developers to work on the same project simultaneously without overwriting each other's work.
A simple way to understand Git is:
"Git is like a timeline of our project. It tracks every code change, who made it, and when. If anything breaks, we can easily go back to any previous version."
Interview Answer
"Git is a distributed version control system used to track changes in source code. It allows multiple developers to collaborate on the same project by maintaining complete version history, supporting branching and merging, and enabling rollback to previous versions whenever required."
Key Features of Git
| Feature | Description |
|---|---|
| Distributed | Every developer has a complete copy of the repository and its history locally. |
| Version Control | Tracks every version of every file and allows easy rollback. |
| Branching & Merging | Enables isolated development and safe merging of changes. |
| Collaboration | Multiple developers can work simultaneously without overwriting each other's work. |
| Rollback | Easily restore previous versions if bugs or issues are introduced. |
Where is Git Used in Automation Testing?
Git is commonly used for:
- Storing Selenium automation scripts
- Managing REST Assured API automation projects
- Tracking changes to test cases
- Sharing automation code with team members
- Integrating with Jenkins for CI/CD
- Connecting with GitHub, GitLab, or Bitbucket
Real-Time Example
In my project, we used Git to manage all Selenium and REST Assured automation scripts. Whenever we developed a new test case or fixed an automation bug, we committed the changes to Git. Every new feature was developed in a separate feature branch. After code review and successful testing, the changes were merged into the main branch through a Pull Request, ensuring high code quality and avoiding conflicts.
Git vs GitHub
Although often used together, Git and GitHub are different.
Interview Answer
"Git is the version control tool that manages code locally, whereas GitHub is a cloud platform that hosts Git repositories and enables collaboration through Pull Requests, code reviews, and CI/CD integration."
Git vs GitHub Comparison
| Git | GitHub |
|---|---|
| Distributed Version Control System | Cloud-based Git hosting platform |
| Runs locally on your computer | Runs online |
| Tracks source code changes | Hosts Git repositories |
| Supports commits, branches, merges | Supports Pull Requests, code reviews, issues |
| Works without internet | Requires internet for collaboration |
| Used for local version control | Used for sharing and collaboration |
Real-Time Example
In my automation project, I maintained all test scripts locally using Git. Once my work was complete, I pushed the changes to GitHub, where my automation lead reviewed the code through a Pull Request before merging it into the main branch. Jenkins then automatically executed the automation suite as part of the CI/CD pipeline.
Benefits of Using Git
Git provides several advantages for software development and test automation.
Version Control
Tracks every change made to the project.
Benefits:
- View previous versions
- Compare changes
- Restore older versions
Collaboration
Allows multiple developers to work on the same project simultaneously without overwriting each other's changes.
Branching and Merging
Developers can:
- Create feature branches
- Develop independently
- Merge changes safely
Offline Access
Since Git is distributed:
- Most operations work offline.
- Synchronization happens later.
Complete Change History
Every commit records:
- What changed
- Who changed it
- When it changed
Lightweight and Fast
Git performs operations like:
- Commit
- Branch
- Merge
- Diff
very efficiently.
CI/CD Integration
Git integrates seamlessly with:
- Jenkins
- GitHub Actions
- GitLab CI/CD
- Azure DevOps
Safe Code Sharing
Repositories can be shared using:
- GitHub
- GitLab
- Bitbucket
Conflict Resolution
Git provides tools to:
- Detect merge conflicts
- Compare file differences
- Resolve conflicts efficiently
Summary of Benefits
| Benefit | Description |
|---|---|
| Version Control | Track every code change |
| Collaboration | Multiple developers work safely |
| Branching & Merging | Isolated development |
| Offline Access | Work without internet |
| Change History | Complete commit history |
| Lightweight & Fast | High performance |
| CI/CD Integration | Works with Jenkins and GitHub Actions |
| Safe Code Sharing | GitHub, GitLab, Bitbucket |
| Conflict Resolution | Detect and resolve merge conflicts |
Real-Time Example
During regression testing, I frequently modified existing automation scripts. Git allowed me to identify who originally wrote the code, review previous commits, and quickly revert to a stable version whenever an issue was introduced.
What is a Repository?
A repository (repo) is a storage location where Git maintains your project files along with the complete history of changes.
It stores:
- Source code
- Commits
- Branches
- Tags
- Git metadata
A repository enables developers to track, review, and restore changes whenever needed.
Interview Answer
"A Git repository stores the project's source code together with its complete version history. It allows developers to manage commits, branches, tags, and previous versions of the project efficiently."
Repository Structure
Project Repository
│
├── Source Code
├── Branches
├── Commits
├── Tags
└── Complete Version History
Local Repository vs Remote Repository
Git repositories are of two types.
Local Repository
A local repository exists on your own computer.
Developers use it to:
- Modify code
- Stage files
- Create commits
- Test changes
Common commands:
git add
git commit
git status
Remote Repository
A remote repository is hosted on a server such as GitHub.
It is used for:
- Collaboration
- Sharing code
- Backup
- CI/CD integration
Common commands:
git push
git pull
git fetch
Comparison
| Local Repository | Remote Repository |
|---|---|
| Stored on your computer | Hosted on GitHub, GitLab, Bitbucket |
| Used for development | Used for collaboration |
| Create commits locally | Share commits with team |
| Works offline | Requires internet |
Typical Workflow
Working Directory
│
git add
▼
Staging Area (index)
│
git commit
▼
Local Repository
│
git push
│
▼
Remote Repository
│
git pull
▼
Other Team Members
Real-Time Example
Throughout the day, I commit my automation scripts to my local repository. Once the feature is completed and verified, I push the commits to GitHub. Other team members then pull the latest changes to keep their local repositories synchronized.
Initializing a Git Repository (git init)
The git init command creates a new Git repository in the current project folder.
Interview Answer
"When starting a new project, I navigate to the project directory and execute
git init. This creates a hidden.gitfolder that enables Git version control for the project."
Syntax
git init
Example
cd SeleniumFramework
git init
What Happens After git init?
Git creates a hidden:
.git
directory containing:
- Commit history
- Branch information
- Configuration
- Repository metadata
Workflow
Project Folder
│
▼
git init
│
▼
.git Directory Created
│
▼
Repository Ready
Next Steps After Initialization
git add .
git commit -m "Initial project setup"
Alternative: Clone an Existing Repository
Instead of creating a new repository, download an existing one:
git clone <repository-url>
Try It: A Real First Session
Here's what the first commits of an automation project look like — this output is from a real run. The .gitignore file tells Git to ignore build output and test artefacts:
# .gitignore
target/
screenshots/
*.log
.idea/
$ git init
Initialized empty Git repository in .../SeleniumFramework/.git/
$ git status --short
?? .gitignore
?? pom.xml
?? src/
$ git add .
$ git status --short
A .gitignore
A pom.xml
A src/test/java/LoginTest.java
$ git commit -m "Initial framework setup"
# later, after editing a test:
$ git status --short
M src/test/java/LoginTest.java
$ git diff --stat
src/test/java/LoginTest.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
??means untracked,Ameans staged for the next commit,Mmeans modified since the last commit.- The project also contained
target/andscreenshots/folders, but they never appeared —.gitignorekept compiled output and failure screenshots out of the repository, which keeps it small and avoids merge conflicts on generated files. - The staging area lets you choose exactly what goes into each commit, for example committing a fixed locator without a half-finished new test.
- Never commit passwords or tokens — keep them in environment variables or CI secrets, and add local config files to
.gitignore.
Next steps: Git Commands Cheat Sheet and The Complete Git Tutorial. Practise Git questions under interview conditions in the Git Interview Simulator.
From Real Projects
In my automation roles I maintained test scripts that several people reviewed and extended — POM classes, the business library and data files all changing at once. That's exactly the situation version control is built for: every change reviewed, traceable and easy to undo. On Canolog, the many forms and screens across sales, inventory, finance and service are where keeping page details in POM classes and reusable steps in a business library paid off. Commit small, focused changes with clear messages.
📚 Official documentation: Git documentation
Frequently Asked Questions (FAQs)
1. What is Git?
Git is a Distributed Version Control System (DVCS) used to track changes in source code. It enables multiple developers to collaborate efficiently by maintaining complete version history, supporting branching and merging, and allowing rollback to previous versions whenever necessary.
2. What is the difference between Git and GitHub?
- Git is a distributed version control system that runs locally and manages source code history.
- GitHub is a cloud platform that hosts Git repositories and provides collaboration features such as Pull Requests, code reviews, issue tracking, and CI/CD integration.
3. What are the main benefits of Git?
Git provides several advantages, including:
- Version Control
- Team Collaboration
- Branching and Merging
- Offline Development
- Complete Change History
- High Performance
- CI/CD Integration
- Safe Code Sharing
- Conflict Resolution
4. What is a repository in Git?
A repository (repo) is a storage location that contains the project's source code along with the complete history of commits, branches, tags, and other Git metadata required for version control.
5. What is the difference between a local repository and a remote repository?
- A local repository resides on your computer and is used for development, staging, and committing changes.
- A remote repository is hosted on platforms such as GitHub and is used for collaboration, sharing code, and maintaining a central copy of the project.
6. What command initializes a Git repository?
Use the following command:
git init
This command creates a hidden .git directory that stores the repository's configuration, branches, commits, and version history, enabling Git to begin tracking the project.