Git & GitHub for Beginners: Complete Guide with Practical Examples
Git & GitHub for Beginners: Complete Guide with Practical Examples
A practical beginner-friendly guide to Git, GitHub, branches, commits, pull requests, merge conflicts and Git workflows for QA testers and SDETs.
Git and GitHub are essential tools for modern software development and testing teams. Whether you are a fresher, QA tester, automation engineer, developer or aspiring SDET, understanding Git can help you manage code, collaborate with teams and maintain automation projects effectively.
Git allows you to track changes in your files and maintain different versions of your project. GitHub provides a platform where Git repositories can be hosted, shared and collaborated on with other team members.
In this complete beginner-friendly guide, you will learn what Git is, what GitHub is, how Git works, important Git commands, branches, commits, pull requests, merge conflicts, practical examples and how testers can use Git in automation projects.
Quick Summary
- Git is a distributed version control system.
- GitHub is a platform for hosting and collaborating on Git repositories.
- The basic Git workflow is Working Directory → Staging Area → Local Repository → Remote Repository.
- Branches allow developers and testers to work on separate changes.
- Pull requests provide a workflow for reviewing and merging changes.
- Git is useful for Selenium, Playwright, API automation and CI/CD projects.
- Testers should understand commands such as status, add, commit, pull, push, merge and diff.
What Is Git?
Git is a distributed version control system used to track changes in files and manage different versions of a project.
Simple Example
Imagine you are developing a Selenium automation framework. You make changes to your login test today, modify the framework tomorrow and accidentally break something the following day.
Without version control, finding and recovering previous working versions can be difficult.
With Git, you can create commits representing different points in the project's history and return to earlier versions when necessary.
What Is GitHub?
GitHub is a platform for hosting Git repositories and collaborating on software projects.
Git and GitHub are related but they are not the same thing.
| Git | GitHub |
|---|---|
| Version control system | Platform for hosting and collaboration |
| Runs locally on your computer | Provides remote repositories |
| Tracks file changes | Hosts Git repositories online |
| Works through Git commands | Provides pull requests, issues and collaboration features |
Why Should Testers Learn Git?
Git is particularly important for automation testers because test scripts and frameworks are software projects too.
A QA or SDET may use Git to:
- Store Selenium or Playwright automation code.
- Track changes to test scripts.
- Create branches for new features.
- Collaborate with developers and testers.
- Review automation code.
- Restore previous versions.
- Manage framework changes.
- Work with CI/CD pipelines.
- Connect repositories with Jenkins or GitHub Actions.
Git Installation
Before using Git commands, install Git on your computer. The official Git documentation provides installation guidance for supported platforms.
After installation, verify it from the terminal:
If Git is installed correctly, the terminal displays the installed Git version.
Learn more about installing Git
Configure Git
After installing Git, configure your name and email address. Git uses this identity when creating commits. The official Git documentation recommends configuring your identity as part of the first-time setup.
You can verify the configuration using:
Git Repository
A Git repository is a project directory that Git tracks.
To create a new Git repository inside an existing project:
This creates a hidden .git directory containing Git's internal repository information.
Git Working Areas
Understanding Git's working areas is important for beginners.
Working Directory → Staging Area → Local Repository → Remote Repository
Working Directory
This is where you create and modify your project files.
Staging Area
The staging area contains changes that you want to include in your next commit.
Local Repository
The local repository stores committed versions of your project on your computer.
Remote Repository
A remote repository can be hosted on platforms such as GitHub and allows team members to collaborate.
First Git Project
Let's create a simple project.
Create a file such as:
Then check the repository status:
Git will show the file as an untracked file.
What Is git status?
The git status command shows the current state of your working directory and staging area.
It can help you identify:
- Modified files
- Untracked files
- Staged files
- Changes that are ready to commit
Git Add
To move a file into the staging area:
To stage all changed files:
The dot means that changes in the current directory are included according to Git's pathspec rules.
Git Commit
A commit records staged changes in the local Git repository.
A good commit message should briefly explain what was changed.
Examples:
View Git History
Use the following command to view previous commits:
A shorter format can be displayed using:
Practical Git Workflow
A basic Git workflow looks like this:
This cycle can be repeated whenever you make a meaningful set of changes.
What Is a Git Branch?
A branch provides an independent line of development. Branches allow developers and testers to work on different changes without immediately modifying the main branch.
Example
A tester could create a branch for a new automation feature while the main branch remains stable.
Creating a Git Branch
To create a new branch:
To switch to the branch:
Modern Git also provides:
You can create and switch to a new branch in one command:
View Branches
The current branch is normally marked in the output.
Rename a Branch
To rename the current branch:
Switch Between Branches
Switching branches allows you to move between different lines of development.
What Is a Remote Repository?
A remote repository is a Git repository stored somewhere outside your local computer, such as a GitHub repository.
You can connect your local repository to a remote repository using:
You can check configured remotes using:
Git Push
The git push command uploads your local commits to a remote repository.
For a new branch:
The -u option establishes an upstream relationship so future pushes can often be performed using a shorter command.
Git Clone
If a project already exists on GitHub, you can download a copy of its repository using:
Cloning is commonly used when joining an existing project.
A new QA team member may clone the company's automation repository before starting work.
Git Pull
The git pull command retrieves changes from a remote repository and integrates them into the current branch.
Before starting work, team members often synchronize their local branch with the latest remote changes according to the team's workflow.
Git Fetch vs Git Pull
| git fetch | git pull |
|---|---|
| Downloads remote updates | Downloads remote updates and integrates them |
| Does not automatically change your current branch | Can update the current branch |
| Useful for inspecting remote changes first | Useful when you want to synchronize directly |
What Is a Pull Request?
A Pull Request (PR) is a request to merge changes from one branch into another branch on a collaborative Git hosting platform.
GitHub describes pull requests as a workflow for proposing, reviewing and eventually merging changes from a branch or fork. :chatgpt-content-reference{index="10"}
Typical Pull Request Workflow
Create a feature branch
Create a separate branch for the required feature or test change.
Make code changes
Develop or modify the required automation code.
Run tests
Run the appropriate tests locally before committing.
Commit the changes
Save the completed changes with a meaningful commit message.
Push the branch
Upload your branch and commits to the remote repository.
Create a pull request
Open a PR from the feature branch to the team's target branch.
Review and merge
Team members review the changes, comments are addressed and the PR is merged according to repository policies.
Git Merge
Merge combines changes from one branch into another branch.
For example, after completing a login automation feature:
The actual merge strategy used by a team may vary depending on repository policies and workflow.
Merge Conflicts
A merge conflict can occur when Git cannot automatically combine changes from different branches, often because different branches modify overlapping parts of the same file.
Example
Two testers modify the same method:
and:
Git may require a developer or tester to decide which changes should remain or how they should be combined.
Basic Conflict Resolution Process
- Run the merge or pull operation.
- Identify files with conflicts.
- Open the conflicted files.
- Review the conflicting sections.
- Keep or combine the correct changes.
- Remove conflict markers.
- Save the file.
- Stage the resolved file.
- Complete the merge according to the workflow.
Git Diff
The git diff command helps you inspect changes that have not been staged.
To inspect staged changes:
Git Restore
Git restore can be used to restore working-tree files.
Be careful when discarding changes because the command can remove modifications that have not been committed elsewhere.
Git Reset
Git reset can move the current branch reference and, depending on the selected mode, modify the staging area and working tree.
Because reset can affect commit history and working state, beginners should understand the selected mode before using it on important work.
Git Revert
Git revert creates a new commit that reverses the effect of an earlier commit.
This is often useful when you want to undo a previously committed change while preserving the existing history.
- restore — restores files or staged content.
- reset — can move the branch reference and alter history depending on the mode.
- revert — creates a new commit that reverses an earlier commit.
.gitignore File
The .gitignore file tells Git which files or directories should generally not be tracked.
A Java automation project might contain:
Depending on the project, configuration files containing passwords, API keys or other secrets should never be committed to a public repository.
GitHub also provides documentation for configuring .gitignore files. :chatgpt-content-reference{index="11"}
Git Tags
Tags can be used to mark specific points in repository history, such as release versions.
Git Stash
Git stash temporarily stores working changes so that you can switch context without committing incomplete work.
To view stashed changes:
To restore the latest stash:
GitHub Repository Structure
A typical automation repository may look like this:
The exact structure depends on the framework and project requirements.
Git Workflow for QA Testers
Let's understand a practical Git workflow for an automation tester.
Clone the Automation Repository
Move Into the Project
Create a Feature Branch
Develop the Test
Create or modify your Selenium, Playwright or API automation code.
Check Changes
Run Tests
Execute the appropriate automation tests locally before committing your changes.
Stage Changes
Commit
Push the Branch
Create Pull Request
Create a pull request from your feature branch to the team's target branch and provide a clear description of the changes and testing performed.
Continue learning: SDET Interview Preparation Roadmap
Git Commands Every Tester Should Know
| Command | Purpose |
|---|---|
| git init | Initialize a repository |
| git clone | Copy a remote repository locally |
| git status | Check repository status |
| git add | Stage changes |
| git commit | Record staged changes |
| git log | View commit history |
| git branch | View or manage branches |
| git switch | Switch branches |
| git merge | Combine branch histories |
| git pull | Fetch and integrate remote changes |
| git push | Upload local commits |
| git fetch | Download remote updates |
| git diff | View changes |
| git stash | Temporarily store working changes |
| git revert | Create a commit that reverses another commit |
Git and CI/CD
Git is an important component of modern CI/CD workflows.
For example, a tester pushes automation code to GitHub. A CI system such as Jenkins can then retrieve the code, build the project and execute automated tests according to the configured pipeline.
GitHub for Automation Testers
GitHub can also help testers demonstrate their practical skills to potential employers.
You can create repositories containing:
- Selenium automation projects.
- Playwright projects.
- API automation projects.
- TestNG frameworks.
- Page Object Model examples.
- SQL practice queries.
- Testing documentation.
- CI/CD pipeline examples.
A well-organized GitHub repository can make your practical work easier for others to review.
How to Create a Good Automation GitHub Repository
A professional automation repository should ideally contain:
- ✓ Clear project name
- ✓ README file
- ✓ Project description
- ✓ Technology stack
- ✓ Setup instructions
- ✓ How to execute tests
- ✓ Project structure
- ✓ Sample test reports where appropriate
- ✓ .gitignore file
- ✓ No passwords or API secrets
Example README Structure
Git Best Practices for Testers
1. Write Meaningful Commit Messages
Prefer:
Instead of:
2. Create Feature Branches
Avoid making every change directly on the main branch when the team workflow expects feature branches.
3. Pull Latest Changes Before Starting Work
Synchronize with the appropriate remote branch according to your team's process.
4. Keep Commits Focused
Try to keep related changes together rather than mixing unrelated modifications into one large commit.
5. Never Commit Secrets
Do not commit passwords, access tokens, private keys or other sensitive credentials.
6. Review Changes Before Committing
This can help catch accidental changes before they enter the repository history.
Related learning: Java Programming for Testers
Git Interview Questions for Testers
1. What is Git?
Git is a distributed version control system used to track changes and manage versions of files.
2. What is GitHub?
GitHub is a platform that hosts Git repositories and provides collaboration features such as pull requests and code review.
3. What is the difference between Git and GitHub?
Git is the version control system, while GitHub is a platform used to host and collaborate on Git repositories.
4. What is a Git repository?
A Git repository is a project managed by Git that contains its tracked files and version history.
5. What is a commit?
A commit records staged changes in the local repository along with a commit message.
6. What is a branch?
A branch is an independent line of development that allows changes to be developed separately from another branch.
7. What is git pull?
Git pull fetches changes from a remote repository and integrates them into the current branch according to the configured Git workflow.
8. What is git push?
Git push uploads local commits to a remote repository.
9. What is git clone?
Git clone creates a local copy of an existing remote repository.
10. What is a merge conflict?
A merge conflict occurs when Git cannot automatically combine changes from different histories, often because overlapping parts of a file were modified differently.
11. What is git stash?
Git stash temporarily stores working changes so that you can change context without committing those incomplete changes.
12. What is .gitignore?
.gitignore specifies files and directories that Git should generally not track.
13. What is a pull request?
A pull request is a request to merge changes from one branch into another branch for review and integration.
14. What is the difference between git fetch and git pull?
Fetch downloads remote updates without automatically integrating them into the current branch, while pull performs a fetch followed by integration according to the configured behavior.
7-Day Git Learning Plan for Testers
| Day | Topics |
|---|---|
| Day 1 | Git fundamentals and installation |
| Day 2 | init, status, add, commit and log |
| Day 3 | Branches and switching |
| Day 4 | GitHub repositories, clone, push and pull |
| Day 5 | Merge, conflicts, fetch and pull requests |
| Day 6 | Stash, revert, restore, .gitignore and tags |
| Day 7 | Build and publish a small automation project |
Practical Project for Beginners
After learning the commands, create a small Selenium or Playwright automation project.
Suggested Project Workflow
- Create an automation project.
- Initialize Git.
- Create a README file.
- Create a .gitignore file.
- Commit the initial framework.
- Create a feature branch.
- Add a login test.
- Commit the test.
- Push the branch to GitHub.
- Create a pull request.
- Review the changes.
- Merge the branch according to your chosen workflow.
This project gives you practical experience that can be discussed during QA and SDET interviews.
Continue your preparation with: Playwright + TypeScript Roadmap
Frequently Asked Questions
Is Git difficult for beginners?
The basic Git workflow is relatively straightforward once you understand working directory, staging area, commits, branches and remote repositories. Regular practice is the best way to become comfortable with Git.
Should testers learn Git?
Git is a practical skill for managing automation code and collaborating with development and QA teams.
Is GitHub required for Selenium?
GitHub is not required to run Selenium, but it is useful for storing, sharing and collaborating on Selenium automation projects.
What Git commands should a fresher know?
Start with git clone, git init, git status, git add, git commit, git log, git branch, git switch, git pull, git push, git merge and git diff. Then learn stash, revert, restore and fetch.
Can Git help in getting an SDET job?
Git itself does not guarantee employment, but Git knowledge is a practical skill for working with automation frameworks and demonstrating software development practices.
Official Resources
Conclusion
Git and GitHub are important skills for anyone entering modern software testing and automation. Testers frequently work with automation frameworks, test scripts, configuration files and CI/CD pipelines, making version control an important part of their daily workflow.
Start by learning the basic workflow:
Once you understand this workflow, practice it with a real Selenium, Playwright or API automation project. Practical usage will help you remember Git commands much more effectively than memorizing them.
If you are preparing for a QA or SDET role, continue with the SDET Interview Preparation Roadmap .
Keep Learning
Explore more career, technology and interview preparation guides on DVGHM.
Related Testing & Career Guides
Keywords: Git and GitHub for beginners, Git tutorial for beginners, Git commands, GitHub tutorial, Git for testers, Git for QA, Git for SDET, Git interview questions, GitHub for testers, Git workflow, Git branches, Git pull request, Git merge conflict, version control for testers